From: Florian Weimer <fweimer@redhat.com>
To: Fangrui Song <maskray@google.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] elf: Simplify version test when searching a versioned symbol
Date: Mon, 02 May 2022 10:40:57 +0200 [thread overview]
Message-ID: <8735hs8gyu.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220501075609.wi3bydt7h27vj6sr@google.com> (Fangrui Song's message of "Sun, 1 May 2022 00:56:09 -0700")
* Fangrui Song:
> On 2022-05-01, Fangrui Song wrote:
>>---
>> elf/dl-lookup.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>>diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
>>index 989b073e4f..3ad6c95d79 100644
>>--- a/elf/dl-lookup.c
>>+++ b/elf/dl-lookup.c
>>@@ -110,14 +110,14 @@ check_match (const char *const undef_name,
>> }
>> else
>> {
>>- /* We can match the version information or use the
>>- default one if it is not hidden. */
>>- ElfW(Half) ndx = verstab[symidx] & 0x7fff;
>>+ /* When the version does not match, allow VER_NDX_GLOBAL fallback when
>>+ resolving relocations (version->hidden==0). Don't bother with the
>>+ check done by the linker: VER_NDX_GLOBAL symbol cannot be hidden.
>>+ */
>>+ ElfW (Half) ndx = verstab[symidx] & 0x7fff;
>> if ((map->l_versions[ndx].hash != version->hash
>> || strcmp (map->l_versions[ndx].name, version->name))
>>- && (version->hidden || map->l_versions[ndx].hash
>>- || (verstab[symidx] & 0x8000)))
>>- /* It's not the version we want. */
>>+ && (version->hidden || ndx != VER_NDX_GLOBAL))
>> return NULL;
>> }
>> }
>> -- 2.36.0.464.gb9c8b46e94-goog
>
> The existing code has a bug.
>
> If a has foo@v1 referencing b.so. If I rebuild b.so and change foo@v1 to
> foo VER_NDX_GLOBAL,
>
> `strcmp (map->l_versions[ndx].name, version->name)` may trigger a null
> pointer dereference:
>
> (rr) p map->l_versions[1]
> $7 = {name = 0x0, hash = 0, hidden = 0, filename = 0x0}
>
> This can be fixed with `!map->l_versions[ndx].name || strcmp (map->l_versions[ndx].name, version->name)`
Hmm. How do we handle VER_NDX_GLOBAL in the dynamic linker?
The if branch has an assert. I think it fires if we drop symbol
versioning completely. I think we should report a proper error for
that.
Should the switch to VER_NDX_GLOBAL also result in an error
(eventually)?
Thanks,
Florian
next prev parent reply other threads:[~2022-05-02 8:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-01 7:46 Fangrui Song
2022-05-01 7:56 ` Fangrui Song
2022-05-02 8:40 ` Florian Weimer [this message]
2022-05-02 18:58 ` Fangrui Song
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=8735hs8gyu.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=maskray@google.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).