mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Timo Teräs" <timo.teras@iki.fi>
To: musl@lists.openwall.com
Cc: "Timo Teräs" <timo.teras@iki.fi>
Subject: [PATCH 3/3] [FYI] fix dynamic linker dso loading
Date: Wed, 10 Jul 2013 16:39:01 +0300	[thread overview]
Message-ID: <1373463541-17170-3-git-send-email-timo.teras@iki.fi> (raw)
In-Reply-To: <1373463541-17170-1-git-send-email-timo.teras@iki.fi>

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



  parent reply	other threads:[~2013-07-10 13:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-10 13:38 [PATCH 1/3] PIE support for arm Timo Teräs
2013-07-10 13:39 ` [PATCH 2/3] Unwind support for ARM EABI Timo Teräs
2013-07-10 17:35   ` Timo Teras
2013-07-10 18:05     ` Rich Felker
2013-07-10 18:41       ` [PATCH v2] " Timo Teräs
2013-07-10 19:55         ` [PATCH v3] " Timo Teräs
2013-07-10 13:39 ` Timo Teräs [this message]
2013-07-10 15:00   ` [PATCH 3/3] [FYI] fix dynamic linker dso loading Rich Felker
2013-07-10 15:47     ` Timo Teras
2013-07-10 16:52       ` Richard Felker
2013-07-10 19:23 ` [PATCH 1/3] PIE support for arm (copyright...) Isaac
2013-07-10 19:28   ` Rich Felker
2013-07-10 21:03     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373463541-17170-3-git-send-email-timo.teras@iki.fi \
    --to=timo.teras@iki.fi \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).