mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Richard Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: [PATCH 3/3] [FYI] fix dynamic linker dso loading
Date: Wed, 10 Jul 2013 12:52:23 -0400	[thread overview]
Message-ID: <20130710165223.GA29800@brightrain.aerifal.cx> (raw)
In-Reply-To: <20130710184725.40e733de@vostro>

On Wed, Jul 10, 2013 at 06:47:25PM +0300, Timo Teras wrote:
> On Wed, 10 Jul 2013 11:00:03 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> 
> > On Wed, Jul 10, 2013 at 04:39:01PM +0300, Timo Teräs wrote:
> > > 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.
> > 
> > I am confused about the motivation for this patch. The program headers
> > are part of the mapping and are never freed.
> 
> static void *map_library(int fd, struct dso *dso)
> {
> 	Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
> ....
> 	ssize_t l = read(fd, buf, sizeof buf);
> ....
> 	ph = (void *)((char *)buf + eh->e_phoff);
> ....
> 	dso->phdr = ph;
> 
> So no, the program headers are not part of the mapping. At least they
> are not setup that way currently.

Indeed, this is purely my fault for failing to review this part of the
patch when it was committed. I was not aware that dso->phdr was being
pointed to the wrong memory; presumably it "happened to work" for some
tests I did at the time. I will fix it.

> Instead dso->phdr points to stack and gets messed up. That's why the:
> -	dso->phdr = ph;
> +	dso->phdr = malloc(phsize);
> +	memcpy(dso->phdr, ph, phsize);
> 
> Perhaps the proper fix would be to map them instead then.

They are already mapped anyway; the pointer into the right offset of
the map is just not setup.

> > > The reclamation fix should be probably something better, as I
> > > believe the same applies to GNU_EH_FRAME phdr.
> > 
> > It definitely does not apply to GNU_EH_FRAME.
> 
> Seems I misunderstood in hurry what the reclaim_gaps really does.
> Probably one of the reasons why it has the "huge hack" comment.. :)
> 
> I believe the "ph->p_type != PT_ARM_EXIDX" additions are not needed
> after all.

Indeed, all that's needed is the correct pointer value. I'll get a
patch committed soon that should fix the issue; please let me know if
other issues persist.

Rich


  reply	other threads:[~2013-07-10 16:52 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 ` [PATCH 3/3] [FYI] fix dynamic linker dso loading Timo Teräs
2013-07-10 15:00   ` Rich Felker
2013-07-10 15:47     ` Timo Teras
2013-07-10 16:52       ` Richard Felker [this message]
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=20130710165223.GA29800@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --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).