Skip to content

Commit 63d0db9

Browse files
Ed Bartoshdomenkozar
Ed Bartosh
authored andcommitted
fix adjusting startPage
startPage is adjusted unconditionally for all executables. This results in incorrect addresses assigned to INTERP and LOAD program headers, which breaks patched executable. Adjusting startPage variable only when startOffset > startPage should fix this. This change is related to the issue NixOS#10 Signed-off-by: Ed Bartosh <[email protected]>
1 parent 29c085f commit 63d0db9

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/patchelf.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
721721
since DYN executables tend to start at virtual address 0, so
722722
rewriteSectionsExecutable() won't work because it doesn't have
723723
any virtual address space to grow downwards into. */
724-
if (isExecutable) {
725-
if (startOffset >= startPage) {
726-
debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
727-
}
724+
if (isExecutable && startOffset > startPage) {
725+
debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage);
728726
startPage = startOffset;
729727
}
730728

0 commit comments

Comments
 (0)