]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libelf: Treat elf_memory image as writable
authorMark Wielaard <mark@klomp.org>
Fri, 18 Oct 2024 14:52:49 +0000 (16:52 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 18 Oct 2024 14:52:49 +0000 (16:52 +0200)
commit81981fdfd8f776508579da60d29e068359c61e6a
tree96d7dec697bd84e57be1bc752926da1f131e9729
parent43179302d7041e562a9df97165ed15c1c2c7bc22
libelf: Treat elf_memory image as writable

There are use cases where the Elf image created by elf_memory is
manipulated, through the libelf interfaces, in place. This doesn't
work anymore since we changed elf_memory to assume the memory is
read-only in elfutils 0.191. commit cc44ac674 ('libelf: Treat
elf_memory as if using ELF_C_READ_MMAP').

The reason for that change was that if elf_memory was given a
read-only memory image then decompressing a section with elf_compress
would crash. Since it directly writes the updated Shdr size. If you do
want to use elf_compress on an Elf created by elf_memory you have make
sure the memory is writable. You can do this for example by using mmap
PROTE_WRITE and MAP_PRIVATE.

* libelf/elf_memory.c (elf_memory): Call
__libelf_read_mmaped_file with ELF_C_READ_MMAP_PRIVATE.
* tests/elfgetzdata.c (main): Use mmap PROT_WRITE and MAP_PRIVATE.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/elf_memory.c
tests/elfgetzdata.c