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 @@ -1019,7 +1019,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
1019
1019
1020
1020
/* Calculate how many bytes are needed out of the additional pages. */
1021
1021
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 ();
1023
1025
debug (" needed pages is %d\n " , neededPages);
1024
1026
if (neededPages * getPageSize () > firstPage)
1025
1027
error (" virtual address space underrun!" );
Original file line number Diff line number Diff line change @@ -48,14 +48,16 @@ src_TESTS = \
48
48
print-execstack.sh \
49
49
modify-execstack.sh \
50
50
rename-dynamic-symbols.sh \
51
+ overlapping-segments-after-rounding.sh \
51
52
empty-note.sh
52
53
53
54
build_TESTS = \
54
55
$(no_rpath_arch_TESTS )
55
56
56
57
TESTS = $(src_TESTS ) $(build_TESTS )
57
58
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
59
61
60
62
TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 STRIP=$(STRIP ) OBJDUMP=$(OBJDUMP ) READELF=$(READELF ) OBJCOPY=$(OBJCOPY )
61
63
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