Skip to content

Commit 6e7079d

Browse files
committed
Seems hackish
1 parent e37f892 commit 6e7079d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ 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)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
rm -rf "${SCRATCH}"
10+
mkdir -p "${SCRATCH}"
11+
12+
cp "${EXEC_NAME}.xz" ${SCRATCH}/
13+
cd ${SCRATCH}
14+
xz --decompress "${EXEC_NAME}.xz"
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
9.91 KB
Binary file not shown.

0 commit comments

Comments
 (0)