diff options
author | Darren Tucker <dtucker@zip.com.au> | 2014-01-17 09:53:24 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2014-01-17 09:53:24 +1100 |
commit | fd994379dd972417d0491767f7cd9b5bf23f4975 (patch) | |
tree | 7148d308a263413c41d896350be1d538d4e01948 | |
parent | 366224d21768ee8ec28cfbcc5fbade1b32582d58 (diff) |
- (dtucker) [aclocal.m4 configure.ac] Add some additional compiler/toolchain
hardening flags including -fstack-protector-strong. These default to on
if the toolchain supports them, but there is a configure-time knob
(--without-hardening) to disable them if necessary. ok djm@
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | aclocal.m4 | 21 | ||||
-rw-r--r-- | configure.ac | 40 |
3 files changed, 58 insertions, 9 deletions
@@ -1,3 +1,9 @@ | |||
1 | 20140117 | ||
2 | - (dtucker) [aclocal.m4 configure.ac] Add some additional compiler/toolchain | ||
3 | hardening flags including -fstack-protector-strong. These default to on | ||
4 | if the toolchain supports them, but there is a configure-time knob | ||
5 | (--without-hardening) to disable them if necessary. ok djm@ | ||
6 | |||
1 | 20140118 | 7 | 20140118 |
2 | - (djm) OpenBSD CVS Sync | 8 | - (djm) OpenBSD CVS Sync |
3 | - djm@cvs.openbsd.org 2014/01/16 07:31:09 | 9 | - djm@cvs.openbsd.org 2014/01/16 07:31:09 |
diff --git a/aclocal.m4 b/aclocal.m4 index 1b3bed790..b1648e4e7 100644 --- a/aclocal.m4 +++ b/aclocal.m4 | |||
@@ -1,4 +1,4 @@ | |||
1 | dnl $Id: aclocal.m4,v 1.9 2013/06/02 21:31:27 tim Exp $ | 1 | dnl $Id: aclocal.m4,v 1.10 2014/01/16 22:53:24 dtucker Exp $ |
2 | dnl | 2 | dnl |
3 | dnl OpenSSH-specific autoconf macros | 3 | dnl OpenSSH-specific autoconf macros |
4 | dnl | 4 | dnl |
@@ -10,7 +10,7 @@ dnl 'check_flag'. | |||
10 | AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{ | 10 | AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{ |
11 | AC_MSG_CHECKING([if $CC supports $1]) | 11 | AC_MSG_CHECKING([if $CC supports $1]) |
12 | saved_CFLAGS="$CFLAGS" | 12 | saved_CFLAGS="$CFLAGS" |
13 | CFLAGS="$CFLAGS $1" | 13 | CFLAGS="$CFLAGS $WERROR $1" |
14 | _define_flag="$2" | 14 | _define_flag="$2" |
15 | test "x$_define_flag" = "x" && _define_flag="$1" | 15 | test "x$_define_flag" = "x" && _define_flag="$1" |
16 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])], | 16 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])], |
@@ -28,6 +28,23 @@ fi], | |||
28 | ) | 28 | ) |
29 | }]) | 29 | }]) |
30 | 30 | ||
31 | dnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag]) | ||
32 | dnl Check that $LD accepts a flag 'check_flag'. If it is supported append | ||
33 | dnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append | ||
34 | dnl 'check_flag'. | ||
35 | AC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{ | ||
36 | AC_MSG_CHECKING([if $LD supports $1]) | ||
37 | saved_LDFLAGS="$LDFLAGS" | ||
38 | LDFLAGS="$LDFLAGS $WERROR $1" | ||
39 | _define_flag="$2" | ||
40 | test "x$_define_flag" = "x" && _define_flag="$1" | ||
41 | AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])], | ||
42 | [ AC_MSG_RESULT([yes]) | ||
43 | LDFLAGS="$saved_LDFLAGS $_define_flag"], | ||
44 | [ AC_MSG_RESULT([no]) | ||
45 | LDFLAGS="$saved_LDFLAGS" ] | ||
46 | ) | ||
47 | }]) | ||
31 | 48 | ||
32 | dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) | 49 | dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) |
33 | dnl Does AC_EGREP_HEADER on 'header' for the string 'field' | 50 | dnl Does AC_EGREP_HEADER on 'header' for the string 'field' |
diff --git a/configure.ac b/configure.ac index d37a211ed..37db0fa7d 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: configure.ac,v 1.547 2013/12/19 00:00:12 dtucker Exp $ | 1 | # $Id: configure.ac,v 1.548 2014/01/16 22:53:24 dtucker Exp $ |
2 | # | 2 | # |
3 | # Copyright (c) 1999-2004 Damien Miller | 3 | # Copyright (c) 1999-2004 Damien Miller |
4 | # | 4 | # |
@@ -15,7 +15,7 @@ | |||
15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | 16 | ||
17 | AC_INIT([OpenSSH], [Portable], [openssh-unix-dev@mindrot.org]) | 17 | AC_INIT([OpenSSH], [Portable], [openssh-unix-dev@mindrot.org]) |
18 | AC_REVISION($Revision: 1.547 $) | 18 | AC_REVISION($Revision: 1.548 $) |
19 | AC_CONFIG_SRCDIR([ssh.c]) | 19 | AC_CONFIG_SRCDIR([ssh.c]) |
20 | AC_LANG([C]) | 20 | AC_LANG([C]) |
21 | 21 | ||
@@ -121,18 +121,35 @@ AC_CHECK_DECL([PR_SET_NO_NEW_PRIVS], [have_linux_no_new_privs=1], , [ | |||
121 | #include <linux/prctl.h> | 121 | #include <linux/prctl.h> |
122 | ]) | 122 | ]) |
123 | use_stack_protector=1 | 123 | use_stack_protector=1 |
124 | use_toolchain_hardening=1 | ||
124 | AC_ARG_WITH([stackprotect], | 125 | AC_ARG_WITH([stackprotect], |
125 | [ --without-stackprotect Don't use compiler's stack protection], [ | 126 | [ --without-stackprotect Don't use compiler's stack protection], [ |
126 | if test "x$withval" = "xno"; then | 127 | if test "x$withval" = "xno"; then |
127 | use_stack_protector=0 | 128 | use_stack_protector=0 |
128 | fi ]) | 129 | fi ]) |
130 | AC_ARG_WITH([hardening], | ||
131 | [ --without-hardening Don't use toolchain hardening flags], [ | ||
132 | if test "x$withval" = "xno"; then | ||
133 | use_stack_protector=0 | ||
134 | use_toolchain_hardening=0 | ||
135 | fi ]) | ||
129 | 136 | ||
137 | # We use -Werror for the tests only so that we catch warnings like "this is | ||
138 | # on by default" for things like -fPIE. | ||
139 | AC_MSG_CHECKING([if $CC supports -Werror]) | ||
140 | saved_CFLAGS="$CFLAGS" | ||
141 | CFLAGS="$CFLAGS -Werror" | ||
142 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])], | ||
143 | [ AC_MSG_RESULT([yes]) | ||
144 | WERROR="-Werror"], | ||
145 | [ AC_MSG_RESULT([no]) | ||
146 | WERROR="" ] | ||
147 | ) | ||
148 | CFLAGS="$saved_CFLAGS" | ||
130 | 149 | ||
131 | if test "$GCC" = "yes" || test "$GCC" = "egcs"; then | 150 | if test "$GCC" = "yes" || test "$GCC" = "egcs"; then |
132 | OSSH_CHECK_CFLAG_COMPILE([-Qunused-arguments -Werror], | 151 | OSSH_CHECK_CFLAG_COMPILE([-Qunused-arguments]) |
133 | [-Qunused-arguments]) | 152 | OSSH_CHECK_CFLAG_COMPILE([-Wunknown-warning-option]) |
134 | OSSH_CHECK_CFLAG_COMPILE([-Wunknown-warning-option -Werror], | ||
135 | [-Wno-unknown-warning-option]) | ||
136 | OSSH_CHECK_CFLAG_COMPILE([-Wall]) | 153 | OSSH_CHECK_CFLAG_COMPILE([-Wall]) |
137 | OSSH_CHECK_CFLAG_COMPILE([-Wpointer-arith]) | 154 | OSSH_CHECK_CFLAG_COMPILE([-Wpointer-arith]) |
138 | OSSH_CHECK_CFLAG_COMPILE([-Wuninitialized]) | 155 | OSSH_CHECK_CFLAG_COMPILE([-Wuninitialized]) |
@@ -143,6 +160,14 @@ if test "$GCC" = "yes" || test "$GCC" = "egcs"; then | |||
143 | OSSH_CHECK_CFLAG_COMPILE([-Wunused-result], [-Wno-unused-result]) | 160 | OSSH_CHECK_CFLAG_COMPILE([-Wunused-result], [-Wno-unused-result]) |
144 | OSSH_CHECK_CFLAG_COMPILE([-fno-strict-aliasing]) | 161 | OSSH_CHECK_CFLAG_COMPILE([-fno-strict-aliasing]) |
145 | OSSH_CHECK_CFLAG_COMPILE([-D_FORTIFY_SOURCE=2]) | 162 | OSSH_CHECK_CFLAG_COMPILE([-D_FORTIFY_SOURCE=2]) |
163 | if test "x$use_toolchain_hardening" = "x1"; then | ||
164 | OSSH_CHECK_CFLAG_COMPILE([-ftrapv]) | ||
165 | OSSH_CHECK_CFLAG_COMPILE([-fPIE]) | ||
166 | OSSH_CHECK_LDFLAG_LINK([-pie]) | ||
167 | OSSH_CHECK_LDFLAG_LINK([-Wl,-z,relro]) | ||
168 | OSSH_CHECK_LDFLAG_LINK([-Wl,-z,now]) | ||
169 | OSSH_CHECK_LDFLAG_LINK([-Wl,-z,noexecstack]) | ||
170 | fi | ||
146 | AC_MSG_CHECKING([gcc version]) | 171 | AC_MSG_CHECKING([gcc version]) |
147 | GCC_VER=`$CC -v 2>&1 | $AWK '/gcc version /{print $3}'` | 172 | GCC_VER=`$CC -v 2>&1 | $AWK '/gcc version /{print $3}'` |
148 | case $GCC_VER in | 173 | case $GCC_VER in |
@@ -169,7 +194,8 @@ if test "$GCC" = "yes" || test "$GCC" = "egcs"; then | |||
169 | # and/or platforms, so we test if we can. If it's not supported | 194 | # and/or platforms, so we test if we can. If it's not supported |
170 | # on a given platform gcc will emit a warning so we use -Werror. | 195 | # on a given platform gcc will emit a warning so we use -Werror. |
171 | if test "x$use_stack_protector" = "x1"; then | 196 | if test "x$use_stack_protector" = "x1"; then |
172 | for t in -fstack-protector-all -fstack-protector; do | 197 | for t in -fstack-protector-strong -fstack-protector-all \ |
198 | -fstack-protector; do | ||
173 | AC_MSG_CHECKING([if $CC supports $t]) | 199 | AC_MSG_CHECKING([if $CC supports $t]) |
174 | saved_CFLAGS="$CFLAGS" | 200 | saved_CFLAGS="$CFLAGS" |
175 | saved_LDFLAGS="$LDFLAGS" | 201 | saved_LDFLAGS="$LDFLAGS" |