Skip to content

Commit b012146

Browse files
committed
Seems hackish
1 parent e37f892 commit b012146

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/patchelf.cc

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

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

tests/Makefile.am

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ src_TESTS = \
4545
add-debug-tag.sh \
4646
empty-note.sh \
4747
print-execstack.sh \
48-
modify-execstack.sh
48+
modify-execstack.sh \
49+
overlapping-segments-after-rounding.sh \
50+
empty-note.sh
4951

5052
build_TESTS = \
5153
$(no_rpath_arch_TESTS)
5254

5355
TESTS = $(src_TESTS) $(build_TESTS)
5456

55-
EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note
57+
EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note \
58+
overlapping-segments-after-rounding.xz
5659

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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; then
10+
rm -rf "${SCRATCH}"
11+
mkdir -p "${SCRATCH}"
12+
13+
cp "${srcdir}/${EXEC_NAME}.xz" ${SCRATCH}/
14+
cd ${SCRATCH}
15+
xz --decompress "${EXEC_NAME}.xz"
16+
17+
${PATCHELF} --force-rpath --remove-rpath --output modified1 "${EXEC_NAME}"
18+
19+
ldd modified1
20+
21+
${PATCHELF} --force-rpath --set-rpath "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" --output modified2 modified1
22+
23+
ldd modified2
24+
fi
9.91 KB
Binary file not shown.

0 commit comments

Comments
 (0)