summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldso/ldso/dl-elf.c36
-rw-r--r--ldso/ldso/readelflib1.c36
2 files changed, 60 insertions, 12 deletions
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 683dad090..a99513700 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -62,7 +62,7 @@ int _dl_map_cache(void)
_dl_cache_size = st.st_size;
_dl_cache_addr = (caddr_t) _dl_mmap(0, _dl_cache_size, PROT_READ, MAP_SHARED, fd, 0);
_dl_close(fd);
- if (_dl_cache_addr == (caddr_t) - 1) {
+ if (_dl_mmap_check_error(_dl_cache_addr)) {
_dl_dprintf(2, "%s: can't map cache '%s'\n",
_dl_progname, LDSO_CACHE);
return -1;
@@ -399,8 +399,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
Elf32_Dyn *dpnt;
struct elf_resolve *tpnt;
ElfW(Phdr) *ppnt;
- char *status;
- char header[4096];
+ char *status, *header;
unsigned long dynamic_info[24];
unsigned long *lpnt;
unsigned long libaddr;
@@ -450,7 +449,16 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
return NULL;
}
- _dl_read(infile, header, sizeof(header));
+ header = _dl_mmap((void *) 0, 4096, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ if (_dl_mmap_check_error(header)) {
+ _dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
+ _dl_internal_error_number = LD_ERROR_MMAP_FAILED;
+ _dl_close(infile);
+ return NULL;
+ };
+
+ _dl_read(infile, header, 4096);
epnt = (ElfW(Ehdr) *) (intptr_t) header;
if (epnt->e_ident[0] != 0x7f ||
epnt->e_ident[1] != 'E' ||
@@ -461,6 +469,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
libname);
_dl_internal_error_number = LD_ERROR_NOTELF;
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -475,6 +484,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_dprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
"\n", _dl_progname, libname);
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -520,6 +530,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_dprintf(2, "%s: can't map %s\n", _dl_progname, libname);
_dl_internal_error_number = LD_ERROR_MMAP_FAILED;
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
libaddr = (unsigned long) status;
@@ -554,6 +565,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_internal_error_number = LD_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -570,6 +582,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
* that are not mapped as part of the file */
map_size = (ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) & PAGE_ALIGN;
+
if (map_size < ppnt->p_vaddr + ppnt->p_memsz)
status = (char *) _dl_mmap((char *) map_size +
(piclib ? libaddr : 0),
@@ -585,6 +598,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_internal_error_number = LD_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -613,6 +627,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_internal_error_number = LD_ERROR_NODYNAMIC;
_dl_dprintf(2, "%s: '%s' is missing a dynamic section\n",
_dl_progname, libname);
+ _dl_munmap(header, 4096);
return NULL;
}
@@ -715,6 +730,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
}
#endif
+ _dl_munmap(header, 4096);
+
return tpnt;
}
@@ -765,7 +782,14 @@ void _dl_dprintf(int fd, const char *fmt, ...)
int num;
va_list args;
char *start, *ptr, *string;
- char buf[2048];
+ static char *buf;
+
+ buf = _dl_mmap((void *) 0, 4096, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ if (_dl_mmap_check_error(buf)) {
+ _dl_dprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
+ _dl_exit(20);
+ }
start = ptr = buf;
@@ -828,6 +852,7 @@ void _dl_dprintf(int fd, const char *fmt, ...)
start = NULL;
}
}
+ _dl_munmap(buf, 4096);
return;
}
@@ -878,4 +903,3 @@ void *_dl_malloc(int size)
return retval;
}
-
diff --git a/ldso/ldso/readelflib1.c b/ldso/ldso/readelflib1.c
index 683dad090..a99513700 100644
--- a/ldso/ldso/readelflib1.c
+++ b/ldso/ldso/readelflib1.c
@@ -62,7 +62,7 @@ int _dl_map_cache(void)
_dl_cache_size = st.st_size;
_dl_cache_addr = (caddr_t) _dl_mmap(0, _dl_cache_size, PROT_READ, MAP_SHARED, fd, 0);
_dl_close(fd);
- if (_dl_cache_addr == (caddr_t) - 1) {
+ if (_dl_mmap_check_error(_dl_cache_addr)) {
_dl_dprintf(2, "%s: can't map cache '%s'\n",
_dl_progname, LDSO_CACHE);
return -1;
@@ -399,8 +399,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
Elf32_Dyn *dpnt;
struct elf_resolve *tpnt;
ElfW(Phdr) *ppnt;
- char *status;
- char header[4096];
+ char *status, *header;
unsigned long dynamic_info[24];
unsigned long *lpnt;
unsigned long libaddr;
@@ -450,7 +449,16 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
return NULL;
}
- _dl_read(infile, header, sizeof(header));
+ header = _dl_mmap((void *) 0, 4096, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ if (_dl_mmap_check_error(header)) {
+ _dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname);
+ _dl_internal_error_number = LD_ERROR_MMAP_FAILED;
+ _dl_close(infile);
+ return NULL;
+ };
+
+ _dl_read(infile, header, 4096);
epnt = (ElfW(Ehdr) *) (intptr_t) header;
if (epnt->e_ident[0] != 0x7f ||
epnt->e_ident[1] != 'E' ||
@@ -461,6 +469,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
libname);
_dl_internal_error_number = LD_ERROR_NOTELF;
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -475,6 +484,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_dprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET
"\n", _dl_progname, libname);
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -520,6 +530,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_dprintf(2, "%s: can't map %s\n", _dl_progname, libname);
_dl_internal_error_number = LD_ERROR_MMAP_FAILED;
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
libaddr = (unsigned long) status;
@@ -554,6 +565,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_internal_error_number = LD_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -570,6 +582,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
* that are not mapped as part of the file */
map_size = (ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) & PAGE_ALIGN;
+
if (map_size < ppnt->p_vaddr + ppnt->p_memsz)
status = (char *) _dl_mmap((char *) map_size +
(piclib ? libaddr : 0),
@@ -585,6 +598,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_internal_error_number = LD_ERROR_MMAP_FAILED;
_dl_munmap((char *) libaddr, maxvma - minvma);
_dl_close(infile);
+ _dl_munmap(header, 4096);
return NULL;
};
@@ -613,6 +627,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
_dl_internal_error_number = LD_ERROR_NODYNAMIC;
_dl_dprintf(2, "%s: '%s' is missing a dynamic section\n",
_dl_progname, libname);
+ _dl_munmap(header, 4096);
return NULL;
}
@@ -715,6 +730,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
}
#endif
+ _dl_munmap(header, 4096);
+
return tpnt;
}
@@ -765,7 +782,14 @@ void _dl_dprintf(int fd, const char *fmt, ...)
int num;
va_list args;
char *start, *ptr, *string;
- char buf[2048];
+ static char *buf;
+
+ buf = _dl_mmap((void *) 0, 4096, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ if (_dl_mmap_check_error(buf)) {
+ _dl_dprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
+ _dl_exit(20);
+ }
start = ptr = buf;
@@ -828,6 +852,7 @@ void _dl_dprintf(int fd, const char *fmt, ...)
start = NULL;
}
}
+ _dl_munmap(buf, 4096);
return;
}
@@ -878,4 +903,3 @@ void *_dl_malloc(int size)
return retval;
}
-