Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 10 Jul 2013 16:39:01 +0300
From: Timo Teräs <timo.teras@....fi>
To: musl@...ts.openwall.com
Cc: Timo Teräs <timo.teras@....fi>
Subject: [PATCH 3/3] [FYI] fix dynamic linker dso loading

The phdr entries need to be allocated from heap, so later calls
to dl_iterate_phdr work properly. Make sure the ARM unwind info
is not freed.
---
This is not exactly intended to be committed, but shows clearly
what is wrong with the current implementation.

The reclamation fix should be probably something better, as I believe
the same applies to GNU_EH_FRAME phdr.

 src/ldso/dynlink.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 7031d03..a956b39 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -293,7 +293,7 @@ static void reclaim(unsigned char *base, size_t start, size_t end)
 static void reclaim_gaps(unsigned char *base, Phdr *ph, size_t phent, size_t phcnt)
 {
 	for (; phcnt--; ph=(void *)((char *)ph+phent)) {
-		if (ph->p_type!=PT_LOAD) continue;
+		if (ph->p_type != PT_LOAD && ph->p_type != PT_ARM_EXIDX) continue;
 		if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
 		reclaim(base, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
 		reclaim(base, ph->p_vaddr+ph->p_memsz,
@@ -327,7 +327,8 @@ static void *map_library(int fd, struct dso *dso)
 		eh->e_phoff = sizeof *eh;
 	}
 	ph = (void *)((char *)buf + eh->e_phoff);
-	dso->phdr = ph;
+	dso->phdr = malloc(phsize);
+	memcpy(dso->phdr, ph, phsize);
 	dso->phnum = eh->e_phnum;
 	for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
 		if (ph->p_type == PT_DYNAMIC)
@@ -338,7 +339,7 @@ static void *map_library(int fd, struct dso *dso)
 			dso->tls_len = ph->p_filesz;
 			dso->tls_size = ph->p_memsz;
 		}
-		if (ph->p_type != PT_LOAD) continue;
+		if (ph->p_type != PT_LOAD && ph->p_type != PT_ARM_EXIDX) continue;
 		if (ph->p_vaddr < addr_min) {
 			addr_min = ph->p_vaddr;
 			off_start = ph->p_offset;
@@ -365,7 +366,7 @@ static void *map_library(int fd, struct dso *dso)
 	base = map - addr_min;
 	ph = (void *)((char *)buf + eh->e_phoff);
 	for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
-		if (ph->p_type != PT_LOAD) continue;
+		if (ph->p_type != PT_LOAD && ph->p_type != PT_ARM_EXIDX) continue;
 		/* Reuse the existing mapping for the lowest-address LOAD */
 		if ((ph->p_vaddr & -PAGE_SIZE) == addr_min) continue;
 		this_min = ph->p_vaddr & -PAGE_SIZE;
@@ -651,7 +652,7 @@ static void find_map_range(Phdr *ph, size_t cnt, size_t stride, struct dso *p)
 {
 	size_t min_addr = -1, max_addr = 0;
 	for (; cnt--; ph = (void *)((char *)ph + stride)) {
-		if (ph->p_type != PT_LOAD) continue;
+		if (ph->p_type != PT_LOAD && ph->p_type != PT_ARM_EXIDX) continue;
 		if (ph->p_vaddr < min_addr)
 			min_addr = ph->p_vaddr;
 		if (ph->p_vaddr+ph->p_memsz > max_addr)
-- 
1.8.3.2

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.