Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()

/* Calculate how many bytes are needed out of the additional pages. */
size_t extraSpace = neededSpace - startOffset;
unsigned int neededPages = roundUp(extraSpace, getPageSize()) / getPageSize();
// Always give one extra page to avoid colliding with segments that start at
// unaligned addresses and will be rounded down when loaded
unsigned int neededPages = 1 + roundUp(extraSpace, getPageSize()) / getPageSize();
debug("needed pages is %d\n", neededPages);
if (neededPages * getPageSize() > firstPage)
error("virtual address space underrun!");
Expand Down
4 changes: 3 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ src_TESTS = \
print-execstack.sh \
modify-execstack.sh \
rename-dynamic-symbols.sh \
overlapping-segments-after-rounding.sh \
empty-note.sh

build_TESTS = \
$(no_rpath_arch_TESTS)

TESTS = $(src_TESTS) $(build_TESTS)

EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note
EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note \
overlapping-segments-after-rounding

TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 STRIP=$(STRIP) OBJDUMP=$(OBJDUMP) READELF=$(READELF) OBJCOPY=$(OBJCOPY)

Expand Down
Binary file added tests/overlapping-segments-after-rounding
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/overlapping-segments-after-rounding.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /bin/sh -e

PATCHELF=$(readlink -f "../src/patchelf")
SCRATCH="scratch/$(basename "$0" .sh)"
READELF=${READELF:-readelf}

EXEC_NAME="overlapping-segments-after-rounding"

if test "$(uname -i)" = x86_64 && test "$(uname)" = Linux; then
rm -rf "${SCRATCH}"
mkdir -p "${SCRATCH}"

cp "${srcdir}/${EXEC_NAME}" "${SCRATCH}/"
cd "${SCRATCH}"

${PATCHELF} --force-rpath --remove-rpath --output modified1 "${EXEC_NAME}"

ldd modified1

${PATCHELF} --force-rpath --set-rpath "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" --output modified2 modified1

ldd modified2
fi