Hi,

On Wed, Nov 11, 2026 at 03:12:21PM +0800, zengliwen wrote:
> When an ELF file is opened with ELF_C_READ_MMAP, its mapping is
> created with PROT_READ.  For native-endian and suitably aligned ELF
> files, the ELF header currently points directly into that mapping.
> 
> elf_update with ELF_C_NULL may update fields in the ELF header while
> calculating the file layout.  This attempts to write to the read-only
> mapping and can cause a segmentation fault.
> 
> Keep a writable copy of the ELF header when the file is opened with
> ELF_C_READ_MMAP, as is already done for section headers.  Cover both
> ELF32 and ELF64, and exercise the read-only mmap path in
> test-manyfuncs.

Thanks so much for looking into this. I forgot about this issue.  Your
fix looks correct, this is precisely what is done for the shdrs.

I am glad the testcase just works with this fix.

> * libelf/elf_begin.c (file_read_elf): Copy the ELF header when using
>   ELF_C_READ_MMAP.
> * tests/test-manyfuncs.c (check_elf): Exercise ELF_C_READ_MMAP.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=33968
> Signed-off-by: zengliwen <[email protected]>

Pushed,

Mark

Reply via email to