]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libelf: Treat elf_memory as if using ELF_C_READ_MMAP
authorMark Wielaard <mark@klomp.org>
Thu, 1 Feb 2024 13:56:18 +0000 (14:56 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 2 Feb 2024 21:34:19 +0000 (22:34 +0100)
commitcc44ac6740797a23cd0af0cb22bd828d569224b8
treec14d5098eb2dbf3f94fece0666fe6417e24d11b8
parentaba8520b1e43d85f52431251232f96384e704cb5
libelf: Treat elf_memory as if using ELF_C_READ_MMAP

An Elf handle created through elf_memory was treated as if opened with
ELF_C_READ. Which means libelf believed it had read the memory itself
and could simply write to it if it wanted (because it wasn't mmaped
directly on top of a file). This causes issues when that memory was
actually read-only. Work around this by pretending the memory was
actually read with ELF_C_READ_MMAP (so directly readable, but not
writable).

Add extra tests to elfgetzdata to check using elf_memory with
read-only memory works as expected.

  * libelf/elf_memory.c (elf_memory): Call
  __libelf_read_mmaped_file with ELF_C_READ_MMAP.
  * tests/elfgetzdata.c (main): Add new "mem" option.
  * tests/run-elfgetzdata.sh: Also run all tests with new
  "mem" option.

https://sourceware.org/bugzilla/show_bug.cgi?id=31225

Reported-by: Derek Bruening <bruening@google.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/elf_memory.c
tests/elfgetzdata.c
tests/run-elfgetzdata.sh