From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3603 Path: news.gmane.org!not-for-mail From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 3/3] [FYI] fix dynamic linker dso loading Date: Wed, 10 Jul 2013 16:39:01 +0300 Message-ID: <1373463541-17170-3-git-send-email-timo.teras@iki.fi> References: <1373463541-17170-1-git-send-email-timo.teras@iki.fi> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1373463539 16237 80.91.229.3 (10 Jul 2013 13:38:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Jul 2013 13:38:59 +0000 (UTC) Cc: =?UTF-8?q?Timo=20Ter=C3=A4s?= To: musl@lists.openwall.com Original-X-From: musl-return-3608-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jul 10 15:39:00 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Uwubi-0008HQ-Co for gllmg-musl@plane.gmane.org; Wed, 10 Jul 2013 15:38:58 +0200 Original-Received: (qmail 1569 invoked by uid 550); 10 Jul 2013 13:38:56 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 1520 invoked from network); 10 Jul 2013 13:38:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=iUtscYRvn6QHK0/HUPB7ZskWaGo9HEgFhL+L6rM2IRI=; b=JfQH1cABydf6Xm85wqCvuTDzdcqyJOkqVpEw7JvHo2m7dJF/OTgBuHSj2KzqK5rV+h iTwvkaPG+22z6z/e5DVxPCiR6g6z2937UUNElPDzY3LkB2xIOmSxZTG27NZlzPbNjjoz q0s02hnSYkGr8u3kIWAepdTAnKLg/HbTukPVOyIY+z2G2HKRKb45ElSBE2O4aGAZLDBy we9AyZYMdBwvlYuFlkleLRMFnIbHz1CrwSLoH31vqb+XGPPR/10wkGxffiB/PeOO1veE 85QdmQJZI5LaF0tiBpKeVkXHo0V87qKbZdSy432Zwu5FcmMuHikYEYkakqB4/HuNfaXl mX4A== X-Received: by 10.15.50.132 with SMTP id l4mr35450752eew.122.1373463524902; Wed, 10 Jul 2013 06:38:44 -0700 (PDT) Original-Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1373463541-17170-1-git-send-email-timo.teras@iki.fi> Xref: news.gmane.org gmane.linux.lib.musl.general:3603 Archived-At: 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