diff options
| author | Mark Wielaard <[email protected]> | 2024-02-01 14:56:18 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2024-02-02 22:34:19 +0100 |
| commit | cc44ac6740797a23cd0af0cb22bd828d569224b8 (patch) | |
| tree | c14d5098eb2dbf3f94fece0666fe6417e24d11b8 /libelf | |
| parent | aba8520b1e43d85f52431251232f96384e704cb5 (diff) | |
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 <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libelf')
| -rw-r--r-- | libelf/elf_memory.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libelf/elf_memory.c b/libelf/elf_memory.c index a47f1d24..13d77cb7 100644 --- a/libelf/elf_memory.c +++ b/libelf/elf_memory.c @@ -46,5 +46,5 @@ elf_memory (char *image, size_t size) return NULL; } - return __libelf_read_mmaped_file (-1, image, 0, size, ELF_C_READ, NULL); + return __libelf_read_mmaped_file (-1, image, 0, size, ELF_C_READ_MMAP, NULL); } |
