summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/binutils/ld/emultempl
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2003-01-24 02:03:03 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2003-01-24 02:03:03 +0000
commit6828b319f6d3bc4ff8ddace75482ca0ce2e61e26 (patch)
tree5a36e768ef35e3f7b8bfe5f6ba8abb6a708645fe /gnu/usr.bin/binutils/ld/emultempl
parent694ce5c08b75389f9c32127ee1aad2f908b2dfec (diff)
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.
Diffstat (limited to 'gnu/usr.bin/binutils/ld/emultempl')
-rw-r--r--gnu/usr.bin/binutils/ld/emultempl/elf32.em4
1 files changed, 4 insertions, 0 deletions
diff --git a/gnu/usr.bin/binutils/ld/emultempl/elf32.em b/gnu/usr.bin/binutils/ld/emultempl/elf32.em
index 394e21b3f7f..509e4aaac63 100644
--- a/gnu/usr.bin/binutils/ld/emultempl/elf32.em
+++ b/gnu/usr.bin/binutils/ld/emultempl/elf32.em
@@ -1459,6 +1459,8 @@ echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
fi
+echo ' ; else if (config.data_bss_contig == true) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xz >> e${EMULATION_NAME}.c
echo ' ; else return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
echo '; }' >> e${EMULATION_NAME}.c
@@ -1480,6 +1482,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
return "ldscripts/${EMULATION_NAME}.xn";
else if (link_info.shared)
return "ldscripts/${EMULATION_NAME}.xs";
+ else if (config.data_bss_contig == true)
+ return "ldscripts/${EMULATION_NAME}.xz";
else
return "ldscripts/${EMULATION_NAME}.x";
}