Skip to content

Commit 0bd5fc2

Browse files
committed
This is a project to modify executables so that they do not have any
executable regions which are writable. If a section of an executable is writable and executable, it is much easier for errant code to modify the executable's behavior. Two current areas in shared library environments which have this critical problem are the GOT (Global Offset Table) and PLT (Procedure Linkage Table). The PLT is required to be executable and both GOT and PLT are writable on most architectures. On most ELF architecture machines this would cause shared libraries to have data and BSS marked as executable. Padding to the linker script for programs and shared libraries/objects to isolate the GOT and PLT into their own load sections in the executables. This allows only the text(readonly) region and the PLT region to be marked executable with the normal data and BSS not marked as executable. The PLT region is still marked executable on most architectures because the PLT lives in the "data" or "BSS" regions and the dynamic loader will need to modify it. Since the GOT and PLT should only ever be written by the dynamic linker, it will be modified to mprotect those regions so that they are not writable during normal execution. If the dynamic linker needs to modify the regions later, (eg for lazy binding), it will mprotect the region, make the necessary changes, and mprotect it back. Since it is possible to receive a signal which would interrupt the program flow and perhaps cause the dynamic linker to modify the same (or nearby) PLT references, it is now necessary for signals to be blocked for the duration of the mprotect. This diff was omitted from the original commit, this implements the -Z option to produce traditional (non protected) executables.
1 parent aae0ce4 commit 0bd5fc2

File tree

1 file changed

+4
-0
lines changed
  • gnu/usr.bin/binutils/ld/emultempl

1 file changed

+4
-0
lines changed

gnu/usr.bin/binutils/ld/emultempl/elf32.em

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,8 @@ echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
14591459
sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
14601460
fi
14611461

1462+
echo ' ; else if (config.data_bss_contig == true) return' >> e${EMULATION_NAME}.c
1463+
sed $sc ldscripts/${EMULATION_NAME}.xz >> e${EMULATION_NAME}.c
14621464
echo ' ; else return' >> e${EMULATION_NAME}.c
14631465
sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
14641466
echo '; }' >> e${EMULATION_NAME}.c
@@ -1480,6 +1482,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
14801482
return "ldscripts/${EMULATION_NAME}.xn";
14811483
else if (link_info.shared)
14821484
return "ldscripts/${EMULATION_NAME}.xs";
1485+
else if (config.data_bss_contig == true)
1486+
return "ldscripts/${EMULATION_NAME}.xz";
14831487
else
14841488
return "ldscripts/${EMULATION_NAME}.x";
14851489
}

0 commit comments

Comments
 (0)