Bug 29864 - __libc_start_main() should obtain program headers address (_dl_phdr) from the auxv, not the ELF header.
Summary: __libc_start_main() should obtain program headers address (_dl_phdr) from the...
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.37
Assignee: Adhemerval Zanella
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-07 11:37 UTC by Yago Gutiérrez
Modified: 2023-01-12 16:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch file with my proposed solution. (1.02 KB, patch)
2022-12-07 11:37 UTC, Yago Gutiérrez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yago Gutiérrez 2022-12-07 11:37:51 UTC
Created attachment 14487 [details]
A patch file with my proposed solution.

The ELF specification declares a field in the ELF header to contain the offset inside the binary at which there will be found the program headers table: phoff. Since a segment may see its in-memory size differ from its in-file size (or the binary may have holes), in-memory offsets are bound to differ too from their in-file counterparts, and hence we may commit an error using base + phoff to find the address of the phdr's, failing miserably with a segmentation fault with a perfectly valid ELF.
Given that the kernel so nicely provides this piece of information in the auxiliar vector, I think it would be best to use it by default, recurring to other ways only when this field is mysteriously ommited from it or there is no auxiliar vector at all.
Comment 1 Adhemerval Zanella 2022-12-08 16:20:17 UTC
Patch looks ok. Ideally, we dl_phdr would be in relro section but we do not for other globals. Could you send it to libc-alpha? All patches are discussed there.
Comment 2 Yago Gutiérrez 2022-12-08 17:07:59 UTC
Yes, it has already been sent to the mailing list, unless I made something wrong... I don't know, this is my first time submitting a patch.
Comment 3 Adhemerval Zanella 2022-12-08 17:14:06 UTC
Yeah, I saw it now.
Comment 4 Adhemerval Zanella 2023-01-12 16:55:48 UTC
Fixed on 2.37.