Robert Connolly robert at
Wed Aug 8 09:13:12 PDT 2007

I finally updated the ssp.txt hint for gcc4. Please add it.

-------------- next part --------------
AUTHOR:		Robert Connolly <robert at linuxfromscratch dot org> (ashes)

DATE:		2007-08-08

LICENSE:	Public Domain

SYNOPSIS:	Stack Smashing Protector, and _FORTIFY_SOURCE


Stack Smashing Protector (SSP) is a C, C++, Obj, and Obj++ debugging/security
extension for GCC. SSP was originally developed by IBM for protecting
applications from the single largest class of program attacks, and it has
since been adopted by many security oriented operating systems. More recently
SSP was officially added to GCC, Glibc, and uClibc. This recent addition
modified the original SSP implementation to add SSP to Tread Local Storage,
so that each thread can be guarded separately. The IBM homepage for SSP is
Another nice description is here:
"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.
_FORTIFY_SOURCE is a Glibc feature which adds memory and string function
protection. There is no home site for this feature, but it is described well
on this page:

GCC-4.1 (or newer) for SSP and _FORTIFY_SOURCE.
Glibc-2.4 (or newer) for SSP and _FORTIFY_SOURCE.

The standard version of SSP uses /dev/urandom directly. When a whole system is
built with SSP this tends to consume all the kernel entropy. /dev/erandom is
reccomended for SSP to conserve kernel entropy. See the entropy.txt hint for
this at:


		Stack Smashing Protector

- Stack Smashing Protector

The GCC options for SSP are -fstack-protector, -fstack-protector-all, and
-Wstack-protector. The -fstack-protector option only protects functions with
character arrays, and is generally not recomended. The -fstack-protector-all
option protects all functions. The -Wstack-protector option will produce a
warning about any functions which are not protected. This warning can occure
in functions with buffers smaller than 8 bytes.

The '--param=ssp-buffer-size=' GCC option controls the minimum buffer size
protected by SSP.

There have been reports of problems with SSP and 'gcc -O3' with Python. It
may or may not cause problems in other packages with -O3.

The GCC manual page says to avoid using '-Wp' whenever possible, so use


# In chapter 5 of the LFS book, you don't need to do anything different.

Chapter 6

# - Glibc
# Make SSP use /dev/erandom:

sed -i 's@/dev/urandom@/dev/erandom@' sysdeps/unix/sysv/linux/dl-osinfo.h

# The following does not work with Glibc-2.6.1... the build will go into an
# infinite loop. This does work with Glibc-2.5.

# Glibc's libraries can not be built with SSP or _FORTIFY_SOURCE, but the
# applications can. This is optional.
# The 'nscd' program is built with -fstack-protector by default. The following
# command will make -fstack-protector-all be used instead, for better
# protection:

sed -i 's/fstack-protector/&-all/' nscd/Makefile

# After running ./configure, the follwing command will tell Glibc to build
# the libraries but not the application programs:

echo 'build-programs=no' > configparms

# Then run 'make' normally. Now the programs can be built with SSP and
# _FORTIFY_SOURCE. You can build the applications with SSP and/or
# _FORTIFY_SOURCE... both are optional and independent of eachother. To build
# Glibc's applications with both SSP and _FORTIFY_SOURCE use the following
# command after building the libraries:

echo 'CC = gcc -fstack-protector-all -D_FORTIFY_SOURCE=2
CXX = g++ -fstack-protector-all -D_FORTIFY_SOURCE=2
' > configparms

# Then run 'make' again.

# The CC and CXX variables are used instead of CFLAGS and CXXFLAGS because
# CFLAGS and CXXFLAGS are sometimes ignored by the Glibc build system.

# The Glibc test suite should pass as if -fstack-protector-all and
# -D_FORTIFY_SOURCE=2 were not used. Continue to test and install Glibc
# normally.

# - GCC
# To make GCC use SSP by default get:
#	gcc-4.1.2-fstack_protector-1.patch
# or
#	gcc-4.2.1-fstack_protector.patch

patch -Np1 -i gcc-4.1.2-fstack_protector-1.patch

# This SSP patch adds -fstack-protector-all as the default for C, C++, OBJC,
# and OBJC++.

# To make GCC use -D_FORTIFY_SOURCE=2 by default get (this patch works for
# gcc-4.2.1 too):
#	gcc-4.1.2-fortify_source-1.patch

# If you want to build GCC itself with SSP and _FORTIFY_SOURCE, then use
# 'make bootstrap'. If you want to build Binutils with SSP and _FORTIFY_SOURCE
# then rebuild and reinstall it. Add --disable-werror to work around warnings
# caused by _FORTIFY_SOURCE.

# - Grub
env CC="gcc -fno-stack-protector -U_FORTIFY_SOURCE" ./configure...

# ---------
# Chapter 8
# ---------

# - Kernel
# The recent 2.6 kernels will detect SSP and disable it. _FORTIFY_SOURCE can
# be built into the kernel, or you can disable it with:
# make CC="gcc -U_FORTIFY_SOURCE"

# -----
# -----

# - Arts
# mcopidl from Arts has issues with SSP. Use the following command to disable
# propolice just for the mcopidl program.

sed -e 's/^KDE_CXXFLAGS .*$/& -fno-stack-protector/' \
	-i mcopidl/

# ========
# Testing
# ========
# The Glibc test suite includes tests for SSP and _FORTIFY_SOURCE.
# Additional regression tests can be found in NetBSD's regress/lib/libc/ssp/.
# There are a couple tests in the 'paxtest' package which may also be usefull.


* 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++.
* New glibc patches.
* Added note about using 2.6.7 frandom patch for older kernels.
* XFree86 patch works with Xorg too.
* -O3 optimizations are fine.
* Added -O2 to Grub's CFLAGS.
* Updated for LFS-6.0.
* Removed sspspecs patches, replaced with Perl command/script.
* Removed obsolete kernel patch.
* Added sed command for version.c.
* Added fstack_protector patch to Glibc in chapter 6.
* Add note for -O3 and Python.
* Fixed misspellings.
* Added --no-backup-if-mismatch to patch command.
* Fix commands for LFS-6.0.
* Added arc4random.
* Added note for "ProPoliceSupport YES" in Xorg.
* Added sed for Arts.
* Finally updated for Glibc-2.4+ and GCC-4.1.
* Removed Libsafe. It's own docs explain how to install it well.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the hints mailing list