Robert Connolly robert at
Mon Nov 22 17:43:27 PST 2004

Hello. Please update this attached hint. I just changed the patch versions, 
nothing else new.
-------------- next part --------------
AUTHOR:		Robert Connolly <robert at linuxfromscratch dot org> (ashes)

DATE:		2004-11-21

LICENSE:	Public Domain

SYNOPSIS:	Smashing Stack Protector and Libsafe


Smashing Stack Protector is a C and C++ security extension for GCC.
Libsafe prevents format string attacks.

Based on StackGaurd, SSP was developed by IBM for protecting applications
from stack smashing attacks. This is the single largest class of attacks and
many security oriented vendors have added it to their default compiler. The
overhead lost to this type of guard is minimal. In practice if the entire
system is built with SSP users shouldn't notice any difference in preformance.

The official homepage for ProPolice Smashing Stack Srotector is at:\
"Hiroaki Etoh's ProPolice is a modification to the GNU C compiler that places a
random canary between any stack allocated character buffers and the return
pointer [5]. It then validates that the canary has not been dirtied by an
overflowed buffer before the function returns. ProPolice can also reorder local
variables to protect local pointers from being overwritten in a buffer overflow.
Also see:

The frandom kernel patch is now required for SSP. This provides the erandom
device and sysctl interface. Using erandom stops a serious entropy depletion
problem while still providing urandom quality random bytes. Idealy you should
reboot an frandom kernel before installing SSP, but SSP will build without it.
If the erandom sysctl interface is missing from the system (vanilla kernel)
then /dev/urandom will be used; if /dev/urandom is missing (chroot) then
gettimeofday() will be used. Read this to install frandom:
You will need the header from the frandom patch installed to build glibc.



		Extra security patches


Smashing Stack Protector

The GCC patch will add -fstack-protector-all, -fstack-protector, and
-fno-stack-protector to GCC extensions for C and C++; and
__guard_setup and __stack_smash_handler are defined in libgcc2.c. This code is
supplied by IBM, I have changed one definition to enable libc functions, and
added "ssp" to the version string. The gcc2 patch is only needed if you plan to
use gcc2 to build the kernel, and want stack protection in the kernel.

If any of these links are broken look for a newer version.

*** All of these patches are in:\
For example: hlfs-patches-20041121.tar.bz2

Note: gcc-3.3 patches apply to gcc-3.3.* too. Likewise with gcc-3.4 patches.\

The Glibc patch will define __guard_setup and __stack_smash_handler in
so the kill function can be kept in a shared object. In the Glibc patch the
erandom device is used to gather a small amount of random bits for the gaurd
value. /dev/log will also need to be present in chroot for syslog to log stack
overflows. It is reccomended intrusion detection systems monitor the system
logs for these alerts.\
	glibc-2.3.4-ssp_frandom-5.patch # This works for glibc-2.3.3 too.

This GCC Specs patch adds -fstack-protector-all to GCC's default compiler flags.
Filters prevent libraries and the kernel from being built with unnessesary
smash symbols. This patch will build all main executables with stack protection.
This patch makes using stack protector almost transparent. This gcc2 patch is
not nessesary for anyone using gcc3 as their main compiler, it is provided for

The Linux kernel patch adds support to the Linux kernel for smash symbols. It
can only build with -fstack-protector, not -fstack-protector-all, and is
therefore excluded from the default specs in the sspspecs patch.\
        linux-2.4.27-ssp-1.patch # or
        linux-2.6.5-ssp-1.patch # This still works on newer 2.6 kernels.

Do not use older versions than these patches, a new define was added. These
patches should apply to old kernels if you are using an older version.\
        linux-2.4.27-frandom-2.patch # or

In the entropy.txt hint there is a libarc3library using frandom, which
has a patch for Mktemp. See entropy.txt for more details.

The XFree86 patch disables stack protection for some modules. \

And for LFS-6\

Extra security patches
This patch fixes a bug in both glibc-2.3.2 and glibc-2.3.3. This bug can be
reproduced by bind9's testsuite.\

This patch adds a sanity check to malloc. Backported from the Owl project.

Note: This patch was integrated in the latest glibc-2.3.4 (cvs) package.\

Official site:

Note: Libsafe is obsolete, you can still use it if you wish.

Libsafe was developed by Avaya Labs to protect against format string
vulnerabilities. Though not widely used it has been widely tested. This
protection can be installed on an already running system, using
to watch applications at runtime for functions which are known to be vulnerable.
This of course only protects dynamically linked applications. There should not
be a noticeable performance decrease, and it also logs to syslog.

We get some errors if we install Libsafe early in the build.
FAIL: g++.dg/expr/anew1.C execution test
FAIL: g++.dg/expr/anew2.C execution test
FAIL: g++.dg/expr/anew3.C execution test
FAIL: g++.dg/expr/anew4.C execution test

FAIL: S-records
FAIL: S-records with constructors

To avoid these errors install Libsafe after GCC in chapter 6. Libsafe is
somewhat obsolete. Most modern software either doesn't use these strings, or
uses them properly. All of the example exploits in exploits/ will fail because
of SSP.


Do not use -O3 (or -O4) optimizations with stack protector or things will
not work.

Chapter 5
Kernel headers
(See under PREREQUISITES above)
patch -Np1 -i ../linux-2.4.27-frandom-2.patch

 - GCC pass 1
If the host system has SSP in Glibc already, then you can patch gcc
here. Otherwise do not. If in doubt, wait until pass two.
 - Glibc
patch -Np1 -i ../glibc-2.3.4-ssp_frandom-5.patch # or 2.3.2's patch

 - GCC pass 2
If you use sspspecs patch then a `make bootstrap` is a good idea too.
patch -Np1 -i ../gcc-3.3-ssp-3.patch
patch -Np1 -i ../gcc-3.3-sspspecs-4.patch

 - Binutils pass 2
Just for the testsuite.
make CFLAGS="-fno-stack-protector" check

Chapter 6
Make sure the frandom header get installed again.

 - Glibc
patch -Np1 -i ../glibc-2.3.4-ssp_frandom-5.patch

 - Binutils
make CFLAGS="-fno-stack-protector" check

 - GCC
patch -Np1 -i ../gcc-3.3-ssp-3.patch
patch -Np1 -i ../gcc-3.3-sspspecs-4.patch

 - Grub
CFLAGS="-fno-stack-protector" ./configure...

 - GCC 2.95.3
If you are only using gcc2 to compile the kernel then don't bother applying
the sspspecs patch to it.
patch -Np1 -i ../gcc-2.95.3-ssp-4.patch

 - Perl
# Perl uses -O3 by default which can cause problems with SSP, reset it
# to use -O2.
env CFLAGS="-O2" ./configure...

Chapter 8
Linux kernel

make mrproper &&
patch -Np1 -i ../linux-2.4.27-ssp-1.patch
patch -Np1 -i ../linux-2.4.27-frandom-2.patch

make menuconfig

make CC="/opt/gcc-2.95.3/bin/gcc -fstack-protector" dep
make CC="/opt/gcc-2.95.3/bin/gcc -fstack-protector" bzImage

There are a couple tests in this package which may also be usefull here.
There are also tests in the libsafe source.

This will test -fstack-protector-all

cat > fail.c << "EOF"
#include <stdio.h>
#include <unistd.h>

int foo(char *blah) {
  char buffer[7];
  sprintf(buffer, "12345678901234567890123456789012345678901234567890");

int main(int argc, char **argv) {
  printf("before foo()\n");
  printf("after foo()\n");

gcc -fstack-protector-all -o fail fail.c &&

This will display the __guard value. It should change each runtime. This will
test erandom/urandom/gettimeofday is working. Test urandom by booting a
vanilla kernel, test gettimeofday by removing /dev/urandom with a vanilla
kernel, or compile this statically linked and `chroot . ./guard-test`.

cat > guard-test.c << "EOF"
extern unsigned long __guard[];
int main () {
        printf("__guard\t=\t0x%08x;\n", __guard[0]);
        return 0;


* Thanks to Hiroaki Etoh for providing the SSP patch to IBM
* Thanks to IBM for providing the SSP patch at
* Thanks to OpenBSD for their XFree86 code.
* Thanks to for this
* Thanks to and for this
* Thanks to for kernel patches.
* Thanks to Avaya Labs for Libsafe
* Thanks to Teemu Tervo for nptl hint
* Thanks to cross compiling hint \
* Thanks to for proof of concept tests.
* Thanks to Eli Billauer for the Frandom suite

* Debut
* Reformat hint
* Reformatted the patches so they're much easier to apply.
* Edit/rewrite hint & synopsis.
* Added caveat.
* Fixed URLS.
* Lite edit
* New bugs found.
* GCC 2.95.3 patches made.
* XFree86-4.3.0 patch made.
* Hint is now Beta - Need more feedback.
* Edit
* Reformatted patches.
* Reformat patches.
* Update/edit hint.
* Add new example tests.
* Reformat patches.
* Add homepage/mirror url.
* Small edit.
* Added Glibc and kernel patches.
* Rewrote install procedure.
* Try to be more informative.
* Removed Gentoo property.
* Added Libsafe.
* Added Pax.
* Added new versions of binutils and glibc.
* Added GCC PIE.
* Rename filename to winter.txt.
* Do not use "Enforce non-executable pages"
* Spell check.
* Fixed URL.
* Added LOPTS to Net-tools.
* Added LDFLAGS to Perl.
* More cflags.
* New tests.
* Renamed hint back to propolice.txt.
* Added back Gentoo property as optional.
* Added HCC
* Cleanup
* Update urls
* Convert propolice to ssp
* Update gcc-3.3.3 and linux-2.6.2 ssp patches
* Update linux-2.6.3 patch and hgcc url
* Add sspspecs patch. Update.
* Added entropy.txt link for erandom.
* Fix more/again for erandom.
* Update some patches.
* New patches.
* Added guard-test.c
* New patches
* Do not use -O3 or -O4
* Use CFLAGS="-O2" for Perl chapter 6.
* Remove frandom mktemp patch.
* Add note about arc4random.
* Update patches, new define for SYSCTL_ERANDOM.
* Fix typos
* Add new Glibc patches with stderr overflow messages.
* Fixed sspspecs patches so they actually work with g++.

More information about the hints mailing list