FreeBSD/SSP

$Id: README.html,v 1.34 2008/04/15 20:39:20 tataz Exp $


THIS PATCH IS STILL BEING WORKED ON! USE IT AT YOUR OWN RISK!

Index:

What is it, technically speaking ?

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_SSPWITH_SSP (world+kernel)Overhead (%)
real319m45.465s323m31.551s1.1%
user180m5.823s182m48.844s1.5%
sys23m18.855s23m50.322s2.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.

How to use it?

Patchset

Patchsets #10 exist both for CURRENT, RELENG_7 and RELENG_6:

  • CURRENT: This patch fbsd8-ssp.diff is derived from the RELENG_7 one but integrates comments from Ruslan Ermilov's review.
  • RELENG_7: It uses GCC 4.2.1 which provides ProPolice. Thus this patch, fbsd7-ssp-glue.patch, simply enables SSP by default; it can be deactivated with the WITHOUT_SSP knob in src.conf(5).
  • RELENG_6: It uses GCC 3.4.6 which does not provide ProPolice and have to be modified. Therefore this patch is splitted in two parts: the "-propolice" (fbsd6-ssp-glue.patch) one which is basically the real ProPolice patch from Hiroaki Etoh that modifies GCC, and the "-glue" (fbsd6-ssp-propolice.patch) one which is the integration of ProPolice into FreeBSD. Those who want to review the patch should look at the latter.
  • How To...

    1. Apply the patch against your FreeBSD source tree:
    2. Build your world as usually, using either:
    3. Your kernel can also make the best of the stack-smashing protection.
    4. Install your world:
      % make installworld
      
    5. To protect your ports with ProPolice, use the USE_SSP knob:
      % cd /usr/port/some/port
      % make -DUSE_SSP install clean
      
      You can add the following line to your make.conf(5) to compile all your ports with ProPolice:
      USE_SSP=yes
      
      Note 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.

    Patchset history

    (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.

    New GCC options

    Once the ProPolice/SSP patch is applied, GCC will support the following options:

    Option -fno-stack-protector-all is understood by the command line parser but it has no meaning.

    Short story

    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.

    Thanks to...

    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.

    I WANT MORE SECURITY ON FREEBSD!

    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 . These were taken from OpenBSD, as far as I know.

    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

    Bugs

    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)).


    Jeremie Le Hen (jeremie at le-hen dot org)