Index:
Theses patches intend to use the ProPolice stack-smashing protection (SSP) on FreeBSD 6-STABLE, 7-STABLE and 8-CURRENT. ProPolice basically prevents exploits that use stack-based buffer overflows by setting a random integer (called the "canary") in the stack right before the return address. It is set in the function's prologue and verified during the epilogue ; if it has changed, then a buffer overflow has occured and the program commits suicide by killing himself with SIGABRT. Both userland and kernel may be protected.
Furthermore local automatic variables are reordered so that overflowing an array would not overwrite other automatic scalar variables belonging to the same function scope. Only functions containing arrays are protected. There is an option to activate the protection for every functions (see below), tough there is no obvious reason to do so.
The performance loss incurred this security feature is really small:
it has been measured to be in an order of 2 or 3 percent.
ProPolice's author performed a serious performance overhead analysis
which is available at http://www.trl.ibm.com/projects/security/ssp/node5.html.
I have personally ran a classical but quite representative benchmark, making
buildworld thrice:
| WITHOUT_SSP | WITH_SSP (world+kernel) | Overhead (%) | |
| real | 319m45.465s | 323m31.551s | 1.1% |
| user | 180m5.823s | 182m48.844s | 1.5% |
| sys | 23m18.855s | 23m50.322s | 2.2% |
OpenBSD has integrated ProPolice into his source-tree in December 2002 and this is used to compile the whole system by default so far. DragonFlyBSD also has imported ProPolice into its tree since December 2003.
Patchsets #10 exist both for CURRENT, RELENG_7 and RELENG_6:
% cd /usr/src % fetch http://tataz.chchile.org/~tataz/FreeBSD/SSP/fbsd6-ssp-propolice.patch % fetch http://tataz.chchile.org/~tataz/FreeBSD/SSP/fbsd6-ssp-glue.patch % patch -p0 < fbsd6-ssp-propolice.patch % patch -p0 < fbsd6-ssp-glue.patch
% cd /usr/src % fetch http://tataz.chchile.org/~tataz/FreeBSD/SSP/fbsd7-ssp-glue.patch % patch -p0 < fbsd7-ssp-glue.patch
% echo "ENABLE_SSP=yes" >> /etc/make.conf % make buildworld
% make buildworld
% echo "options SSP_SUPPORT" >> /sys/i386/conf/MYKERNEL % make buildkernel installkernel KERNCONF=MYKERNEL
% make buildkernel installkernel KERNCONF=MYKERNEL
% make installworld
% cd /usr/port/some/port % make -DUSE_SSP install cleanYou can add the following line to your make.conf(5) to compile all your ports with ProPolice:
USE_SSP=yesNote however that some ports are known to fail to build or run with SSP. See the FAQ for more informations.
NOTE: If you want to go back to a non-SSP system, you should use a trick described in FAQ, because of the nature of this patch.
(2008.04.15) #10 released.
(2008.03.02) #9 released.
(2008.02.20) #8 released.
(2007.12.11) #7 released.
(2007.08.09) #6 released.
(2007.01.21) #5 released.
(2006.11.19) #4 released.
Differences with previous patchset:
(2006.10.22) #3 released.
Differences with previous patchset:
(2006.10.05) #2 released.
Differences with previous patchsets, which
were preventing the patch from being applied cleanly:
(2006.08.22) #1 released.
Differences with previous patchset:
(2006.05.29) #0 released.
Once the ProPolice/SSP patch is applied, GCC will support the following options:
The original GCC patch was created and is maintained by Hiroaki Etoh (etoh at jp dot ibm dot com) at IBM laboratories in Tokyo: http://www.trl.ibm.com/projects/security/ssp/.
It has been ported to FreeBSD 4.x and FreeBSD 5.1 with the help of, among others (whom I have not been able to find names), Dag-Erling Smorgrav (des at FreeBSD dot org): http://www.trl.ibm.com/projects/security/ssp/buildfreebsd.html.
Thijs Eilander (nomad at paranoid dot nl) recently foreported ProPolice to FreeBSD 5.4 and FreeBSD 6.0. You may want to read his page as well, it contains some useful informations: http://www.paranoid.nl/~eilander/freebsd/propolice/.
For the sake of completeness, the ProPolice/SSP patch has also been ported to FreeBSD 4.7 by Yamamoto Takanori: http://ssp4fbsd.sourceforge.jp/.
Finally, I (Jeremie Le Hen (jeremie at le-hen dot org)) decided to provide a more integrated ProPolice patch for FreeBSD 7-CURRENT.
It has been successfully tested on FreeBSD/i386 and FreeBSD/amd64 only. The src/sys/boot/ part should fail to compile for other platforms, but there should be only little work to make it compile correctly.
Pascal Hofstee (caelian at gmail dot com) tested a huge number of successive patchsets I released. He has been very patient. We worked together to make the patch break POLA as little as possible. Thanks to him, I was able to find out the few bits required to make the patch work on amd64.
Olivier Houchard (cognet at FreeBSD dot org) helped me a lot when I began working on this some months ago, he gave me useful advices. Especially he provided me a patch for libpthread and libthr that made open(3) callable very early in constructor functions, before the threading library was full initialized. Furthermore I owe him the trick to move from an SSP-aware system to a not SSP-aware system using LD_PRELOAD ; before that I had to use /rescue to copy files manually.
Joerg Sonnenberger (joerg at britannica dot bec dot de) pointed me out that -O2 compilation is broken with ProPolice because of the implicit -funit-at-time optimization. He reported this to Hiroaki Etoh who fixed the bug shortly.
Kostik Belousov (kostikbel at gmail dot com) explained me the trick when linking statically binaries not being protected by ProPolice/SSP because they do not use any buffer.
I want to thank all alpha and beta testers: Victor Balada Diaz first, Xavier "Bana" Lapie, Jerome "Jethro" Magnin, Ulrich "Neo" Blondel, Stephane "Darksoul" Lapie. If I forgot someone, please forgive me and let me know.
Raphael Poss reviewed my english (I have modified the text since then).
I would also like to thank the OpenBSD project, the DragonFlyBSD project, the Hardened Debian project and the GCC project on which I took some useful ideas.
Since the patch deals with the stack, it doesn't prevent from heap-based
buffer overflows as well as return-to-libc attacks. To harden your FreeBSD
even more, you can use these two patches from Suleiman Souhlal
This first patch randomize the gap before the stack start. This makes
harder to guess stack address for an attacker:
Post: http://lists.freebsd.org/pipermail/freebsd-arch/2005-May/003835.html
Patch: http://people.freebsd.org/~ssouhlal/testing/stackgap-20050527.diff
This second patch is very interesting because it randomizes the location
of mmap(2)'ed dynamic libairies, which makes return-to-libc attacks more
difficult:
Post: http://lists.freebsd.org/pipermail/freebsd-arch/2005-May/003851.html
Patch: http://people.freebsd.org/~ssouhlal/testing/mmap_random-20050528.diff
I would be pleased to get feedback if you find bugs. In such a case, please provide me the version of FreeBSD you are using (the best would be the date at which you sync'ed your sources). I will also need your make.conf(5) and a full output of your failed compilation (use script(1)).