~ubuntu-branches/ubuntu/trusty/hardening-wrapper/trusty-proposed

« back to all changes in this revision

Viewing changes to hardening.make

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-02-18 10:57:52 UTC
  • Revision ID: james.westby@ubuntu.com-20110218105752-e6wc0gymc73jufua
Tags: 1.32
* debian/rules, debian/hardening-wrapper.{prerm,preinst,postinst}:
  remove gcc-4.1 diversions since it has been removed from unstable.
* hardened-cc, hardening.make: add "-Werror=format-security" by default
  (Closes: #587358).
* tests/Makefile.common, tests/format.c: add test for newly added
  "-Werror=format-security" default option.
* hardened-cc, hardening.make: add "--param ssp-buffer-size=4" by
  default to catch smaller character arrays.
* tests/Makefile.common, tests/ssp-buffer-size-{protect,skip}.c:
  add tests for newly added "--param ssp-buffer-size=4" default.
* debian/README.Debian: updated to include newly added options.
* hardened-cc: disable -fstack-protector when -ffreestanding used.
* hardening.make: provide examples for working around build-time
  collisions between "-fPIE" and "-fPIC" (Closes: #596150).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Makefile -*-, you silly Emacs!
2
2
# vim: set ft=make:
3
3
#
4
 
# Copyright (C) 2009-2010 Kees Cook <kees@debian.org>
 
4
# Copyright (C) 2009-2011 Kees Cook <kees@debian.org>
5
5
# License: GPLv2 or newer
6
6
#
7
7
# This file is intended to be included in a Debian rules file so that the
73
73
_HARDENED_PIE_CFLAGS  := -fPIE
74
74
_HARDENED_PIE_LDFLAGS := -fPIE -pie
75
75
 
76
 
_HARDENED_STACKPROTECTOR_CFLAGS := -fstack-protector
 
76
_HARDENED_STACKPROTECTOR_CFLAGS := -fstack-protector --param ssp-buffer-size=4
77
77
 
78
78
# Fortify Source requires that -O2 or higher is used, but that should be
79
79
# handled outside of this include file.
80
80
_HARDENED_FORTIFY_CFLAGS  := -D_FORTIFY_SOURCE=2
81
81
 
82
 
_HARDENED_FORMAT_CFLAGS   := -Wformat -Wformat-security
 
82
_HARDENED_FORMAT_CFLAGS   := -Wformat -Wformat-security -Werror=format-security
83
83
 
84
84
_HARDENED_RELRO_LDFLAGS   := -Wl,-z,relro
85
85
 
110
110
HARDENING_DISABLE_FORMAT_CFLAGS:=-Wno-format-security
111
111
HARDENING_DISABLE_RELRO_LDFLAGS:=-Wl,-z,norelro
112
112
HARDENING_DISABLE_BINDNOW_LDFLAGS:=-Wl,-z,lazy
113
 
# Note: GCC does not have a way to just turn off pie (there is no -nopie)
 
113
# Note: GCC does not have a way to just turn off pie (there is no "-nopie")
114
114
# so if PIE needs to be disabled for a specific target, the CFLAGS and LDFLAGS
115
115
# need to be filtered. For example:
116
116
#   monkey: monkey.c
117
117
#       $(CC) $(filter-out $(HARDENING_DISABLE_PIE_CFLAGS_FILTER),$(CFLAGS)) \
118
118
#             $(filter-out $(HARDENING_DISABLE_PIE_LDFLAGS_FILTER),$(LDFLAGS)) \
119
119
#             $< -o $@
 
120
#
 
121
# Note: when building shared libraries, or with some build frameworks (e.g.
 
122
# cmake) that pass "-fPIC" to everything, the "-fPIE" option must be filtered
 
123
# out to avoid building shared objects that need PIC but end up only with PIE.
 
124
# This is usually indicated by errors at link time that look like this:
 
125
#  relocation R_X86_64_PC32 against symbol `foo' can not be used when making a shared object; recompile with -fPIC
 
126
# In these cases, the CFLAGS can be filtered to exclude "-fPIE" until this
 
127
# is fixed in gcc correctly. For example, on one target:
 
128
#   monkey.o: monkey.c
 
129
#       $(CC) $(filter-out $(HARDENING_DISABLE_PIE_CFLAGS_FILTER),$(CFLAGS)) \
 
130
#             $< -c -o $@
 
131
# In cases where mixed shared objects and executable objects are being built,
 
132
# "-fPIC" needs to actually replace "-fPIE", since gcc won't distinguish
 
133
# between them yet. For example:
 
134
#   export CFLAGS=$(shell dpkg-buildflags --get CFLAGS)
 
135
#   CFLAGS += $(HARDENING_CFLAGS_PIC) \
 
136
#             $(filter-out $(HARDENING_DISABLE_PIE_CFLAGS_FILTER),$(HARDENING_CFLAGS))
 
137
#
120
138
HARDENING_DISABLE_PIE_CFLAGS_FILTER:=$(_HARDENED_PIE_CFLAGS)
121
139
HARDENING_DISABLE_PIE_LDFLAGS_FILTER:=$(_HARDENED_PIE_LDFLAGS)
 
140
HARDENING_CFLAGS_PIC:=-fPIC