Skip to content

Commit 27cbc89

Browse files
authored
Merge pull request #469 from brenoguim/breno.446
Add one extra page to avoid overlapping with next page if its rounded…
2 parents ac212d0 + de3e1f5 commit 27cbc89

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/patchelf.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
10191019

10201020
/* Calculate how many bytes are needed out of the additional pages. */
10211021
size_t extraSpace = neededSpace - startOffset;
1022-
unsigned int neededPages = roundUp(extraSpace, getPageSize()) / getPageSize();
1022+
// Always give one extra page to avoid colliding with segments that start at
1023+
// unaligned addresses and will be rounded down when loaded
1024+
unsigned int neededPages = 1 + roundUp(extraSpace, getPageSize()) / getPageSize();
10231025
debug("needed pages is %d\n", neededPages);
10241026
if (neededPages * getPageSize() > firstPage)
10251027
error("virtual address space underrun!");

tests/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ src_TESTS = \
4848
print-execstack.sh \
4949
modify-execstack.sh \
5050
rename-dynamic-symbols.sh \
51+
overlapping-segments-after-rounding.sh \
5152
empty-note.sh
5253

5354
build_TESTS = \
5455
$(no_rpath_arch_TESTS)
5556

5657
TESTS = $(src_TESTS) $(build_TESTS)
5758

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

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

223 KB
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /bin/sh -e
2+
3+
PATCHELF=$(readlink -f "../src/patchelf")
4+
SCRATCH="scratch/$(basename "$0" .sh)"
5+
READELF=${READELF:-readelf}
6+
7+
EXEC_NAME="overlapping-segments-after-rounding"
8+
9+
if test "$(uname -i)" = x86_64 && test "$(uname)" = Linux; then
10+
rm -rf "${SCRATCH}"
11+
mkdir -p "${SCRATCH}"
12+
13+
cp "${srcdir}/${EXEC_NAME}" "${SCRATCH}/"
14+
cd "${SCRATCH}"
15+
16+
${PATCHELF} --force-rpath --remove-rpath --output modified1 "${EXEC_NAME}"
17+
18+
ldd modified1
19+
20+
${PATCHELF} --force-rpath --set-rpath "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" --output modified2 modified1
21+
22+
ldd modified2
23+
fi

0 commit comments

Comments
 (0)