From: "Siebenborn, Axel" <axel.siebenborn@sap.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: RE: [PATCH] dl_addr: compare addr with sym->st_size.
Date: Wed, 11 Apr 2018 08:07:38 +0000 [thread overview]
Message-ID: <a6d31df49bab482390c8efc3eb727251@sap.com> (raw)
In-Reply-To: <20180410142312.GE3094@brightrain.aerifal.cx>
Hi,
> -----Original Message-----
> From: Rich Felker [mailto:dalias@aerifal.cx] On Behalf Of Rich Felker
> Sent: Dienstag, 10. April 2018 16:23
> To: musl@lists.openwall.com
> Subject: Re: [musl] [PATCH] dl_addr: compare addr with sym->st_size.
>
> On Tue, Apr 03, 2018 at 01:06:09PM +0000, Siebenborn, Axel wrote:
> > Hi,
> > this patch fixes a problem with dl_addr.
> >
> > We found symbols, in cases we should not find a symbol, since the
> > comparison with sym->st_size is missing.
>
> This was intentional, as my understanding of the historical behavior
> on other implementations was that it would do this. If that's
> incorrect we should investigate and document (or find existing
> documentation of) what they really do.
I don't know how the historical behavior was. Maybe you could point me to
some resources.
However, I found that st_size might be 0, if the symbol has no or an unknown
size. How about comparing st_size to zero?
- if (symaddr > addr || symaddr < best)
+ if (symaddr > addr || ((sym->st_size != 0) && ((void*) ((uint8_t*) symaddr + sym->st_size) < addr)) || symaddr < best)
>
> > According to the spec, dl_addr should not return an error in this
> > case. Instead dli_sname and dli_addr should be set to NULL.
>
> OK, I found that part in the man page.
>
> > diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> > index 9bf6924..cc87dc0 100644
> > --- a/ldso/dynlink.c
> > +++ b/ldso/dynlink.c
> > @@ -1958,7 +1958,7 @@ int dladdr(const void *addr, Dl_info *info)
> > && (1<<(sym->st_info&0xf) & OK_TYPES)
> > && (1<<(sym->st_info>>4) & OK_BINDS)) {
> > void *symaddr = laddr(p, sym->st_value);
> > - if (symaddr > addr || symaddr < best)
> > + if (symaddr > addr || (void*) ((uint8_t*) symaddr + sym-
> >st_size) < addr || symaddr < best)
>
> Not all symbols have st_size set. In that case the old "best match"
> behavior should probably be kept unless there's a strong reason not
> to.
>
> > continue;
> > best = symaddr;
> > bestsym = sym;
> > @@ -1967,13 +1967,16 @@ int dladdr(const void *addr, Dl_info *info)
> > }
> > }
> >
> > - if (!best) return 0;
> > -
> > - if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
> > - best = p->funcdescs + (bestsym - p->syms);
> > -
> > info->dli_fname = p->name;
> > info->dli_fbase = p->map;
> > + if (!best) {
> > + info->dli_sname = 0;
> > + info->dli_saddr = 0;
> > + return 0
>
> This is missing a ; so it seems you tested a slightly different patch..?
Sorry, that's embarrassing. I slightly refactored after testing.
This line should be:
+ return 1;
>
> > + }
> > +
> > + if ( DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
> > + best = p->funcdescs + (bestsym - p->syms);
> > info->dli_sname = strings + bestsym->st_name;
> > info->dli_saddr = best;
>
> Otherwise this looks ok but I haven't tested it.
>
> Rich
Here is the complete patch:
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 9bf6924..2801416 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1958,7 +1958,7 @@ int dladdr(const void *addr, Dl_info *info)
&& (1<<(sym->st_info&0xf) & OK_TYPES)
&& (1<<(sym->st_info>>4) & OK_BINDS)) {
void *symaddr = laddr(p, sym->st_value);
- if (symaddr > addr || symaddr < best)
+ if (symaddr > addr || ((sym->st_size != 0) && ((void*) ((uint8_t*) symaddr + sym->st_size) < addr)) || symaddr < best)
continue;
best = symaddr;
bestsym = sym;
@@ -1967,13 +1967,16 @@ int dladdr(const void *addr, Dl_info *info)
}
}
- if (!best) return 0;
-
- if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
- best = p->funcdescs + (bestsym - p->syms);
-
info->dli_fname = p->name;
info->dli_fbase = p->map;
+ if (!best) {
+ info->dli_sname = 0;
+ info->dli_saddr = 0;
+ return 1;
+ }
+
+ if ( DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
+ best = p->funcdescs + (bestsym - p->syms);
info->dli_sname = strings + bestsym->st_name;
info->dli_saddr = best;
Regards,
Axel
next prev parent reply other threads:[~2018-04-11 8:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 13:06 Siebenborn, Axel
2018-04-10 7:22 ` FW: " Siebenborn, Axel
[not found] ` <20180410142312.GE3094@brightrain.aerifal.cx>
2018-04-11 8:07 ` Siebenborn, Axel [this message]
2018-04-13 1:01 ` Rich Felker
2018-04-13 10:16 ` Siebenborn, Axel
2018-05-16 8:16 ` Siebenborn, Axel
2018-05-16 23:16 ` Rich Felker
2018-05-17 2:06 ` William Pitcock
2018-06-27 20:02 ` Rich Felker
2018-06-28 15:51 ` 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=a6d31df49bab482390c8efc3eb727251@sap.com \
--to=axel.siebenborn@sap.com \
--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).