File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -960,7 +960,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
960
960
961
961
/* Calculate how many bytes are needed out of the additional pages. */
962
962
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 ();
964
966
debug (" needed pages is %d\n " , neededPages);
965
967
if (neededPages * getPageSize () > firstPage)
966
968
error (" virtual address space underrun!" );
Original file line number Diff line number Diff line change @@ -45,14 +45,17 @@ src_TESTS = \
45
45
add-debug-tag.sh \
46
46
empty-note.sh \
47
47
print-execstack.sh \
48
- modify-execstack.sh
48
+ modify-execstack.sh \
49
+ overlapping-segments-after-rounding.sh \
50
+ empty-note.sh
49
51
50
52
build_TESTS = \
51
53
$(no_rpath_arch_TESTS )
52
54
53
55
TESTS = $(src_TESTS ) $(build_TESTS )
54
56
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
56
59
57
60
TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 STRIP=$(STRIP ) OBJDUMP=$(OBJDUMP ) READELF=$(READELF ) OBJCOPY=$(OBJCOPY )
58
61
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments