libelf: Fix some issues with ELF_C_RDWR_MMAP.
authorMark Wielaard <mark@klomp.org>
Sun, 12 Aug 2018 13:35:18 +0000 (15:35 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 12:25:22 +0000 (14:25 +0200)
commitfb0457f4671e7e0f8331453348005ed6beab275e
tree5efa18a7afd9543e644e4e2ab2b14a4d9f887498
parenta1e892e920bbde60a9daa1f98c105c227ee7427d
libelf: Fix some issues with ELF_C_RDWR_MMAP.

When ELF_C_RDWR_MMAP is used libelf might have to write overlapping memory
when moving the section data or headers. Make sure to use memmove, not
memcpy. Also the size of the underlying file might have to change. That
means we will have to also extend the mmap region with mremap. Since we
are using direct pointers into the mmapped area we cannot move the mmap,
only extend it. This might still fail if there is not enough free memory
available to extend the mmap region.

Two new test programs have been added. elfcopy which copies a whole elf
file (using either ELF_C_WRITE or ELF_C_WRITE_MMAP). And addsections which
adds new sections to an existing ELF file (using either ELF_C_RDWR or
ELF_C_RDWR_MMAP). The newly added test will fail under valgrind without
the fixes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf32_updatefile.c
libelf/elf_update.c
tests/ChangeLog
tests/Makefile.am
tests/addsections.c [new file with mode: 0644]
tests/elfcopy.c [new file with mode: 0644]
tests/run-copyadd-sections.sh [new file with mode: 0755]