File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -985,7 +985,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
985
985
986
986
/* Calculate how many bytes are needed out of the additional pages. */
987
987
size_t extraSpace = neededSpace - startOffset;
988
- unsigned int neededPages = roundUp (extraSpace, getPageSize ()) / getPageSize ();
988
+ // Always give one extra page to avoid colliding with segments that start at
989
+ // unaligned addresses and will be rounded down when loaded
990
+ unsigned int neededPages = 1 + roundUp (extraSpace, getPageSize ()) / getPageSize ();
989
991
debug (" needed pages is %d\n " , neededPages);
990
992
if (neededPages * getPageSize () > firstPage)
991
993
error (" virtual address space underrun!" );
Original file line number Diff line number Diff line change @@ -47,14 +47,16 @@ src_TESTS = \
47
47
print-execstack.sh \
48
48
modify-execstack.sh \
49
49
rename-dynamic-symbols.sh \
50
+ overlapping-segments-after-rounding.sh \
50
51
empty-note.sh
51
52
52
53
build_TESTS = \
53
54
$(no_rpath_arch_TESTS )
54
55
55
56
TESTS = $(src_TESTS ) $(build_TESTS )
56
57
57
- EXTRA_DIST = no-rpath-prebuild $(src_TESTS ) no-rpath-prebuild.sh invalid-elf endianness empty-note
58
+ EXTRA_DIST = no-rpath-prebuild $(src_TESTS ) no-rpath-prebuild.sh invalid-elf endianness empty-note \
59
+ overlapping-segments-after-rounding
58
60
59
61
TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 STRIP=$(STRIP ) OBJDUMP=$(OBJDUMP ) READELF=$(READELF ) OBJCOPY=$(OBJCOPY )
60
62
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 && 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
You can’t perform that action at this time.
0 commit comments