From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH v2] elf: Fix GL(dl_phdr) and GL(dl_phnum) for static builds [BZ #29864]
Date: Fri, 3 Feb 2023 11:04:03 -0300 [thread overview]
Message-ID: <29faa59c-1433-7b09-1362-34171a5983af@linaro.org> (raw)
In-Reply-To: <a94a6cbeaa69520d9e639fe480ed97024dcf4dbc.camel@physik.fu-berlin.de>
On 02/02/23 06:36, John Paul Adrian Glaubitz wrote:
> Hi Adhemveral!
>
> On Thu, 2023-01-12 at 11:44 -0300, Adhemerval Zanella wrote:
>> The 73fc4e28b9464f0e refactor did not add the GL(dl_phdr) and
>> GL(dl_phnum) for static build, relying on the __ehdr_start symbol,
>> which is always added by the static linker, to get the correct values.
>>
>> This is problematic in some ways:
>>
>> - The segment may see its in-memory size differ from its in-file
>> size (or the binary may have holes). The Linux has fixed is to
>> provide concise values for both AT_PHDR and AT_PHNUM (commit
>> 0da1d5002745c - "fs/binfmt_elf: Fix AT_PHDR for unusual ELF files")
>>
>> - Some archs (alpha for instance) the hidden weak reference is not
>> correctly pulled by the static linker and __ehdr_start address
>> end up being 0, which makes GL(dl_phdr) and GL(dl_phnum) have both
>> invalid values (and triggering a segfault later on libc.so while
>> accessing TLS variables).
>>
>> The safer fix is to just restore the previous behavior to setup
>> GL(dl_phdr) and GL(dl_phnum) for static based on kernel auxv. The
>> __ehdr_start fallback can also be simplified by not assuming weak
>> linkage (as for PIE).
>>
>> The libc-static.c auxv init logic is moved to dl-support.c, since
>> the later is build without SHARED and then GLRO macro is defined
>> to access the variables directly.
>>
>> The _dl_phdr is also assumed to be always non NULL, since an invalid
>> NULL values does not trigger TLS initialization (which is used in
>> various libc systems).
>>
>> Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu.
>>
>> * Changes from v1:
>> - Removed auxv_values implicit initialization.
>> - Removed unused header inclusion.
>
> Any chance this fix can be backported to 2.36?
Done.
prev parent reply other threads:[~2023-02-03 14:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-12 14:44 Adhemerval Zanella
2023-01-12 14:46 ` Florian Weimer
2023-02-02 9:36 ` John Paul Adrian Glaubitz
2023-02-03 14:04 ` Adhemerval Zanella Netto [this message]
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=29faa59c-1433-7b09-1362-34171a5983af@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=libc-alpha@sourceware.org \
/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).