ref: 70c85915eace83142b84e4f65f5db421cf0c09e3
parent: 8f6aaf97498ff7edc0dcb30192542b4d5924411c
author: Mans Rullgard <mans@mansr.com>
date: Sat Aug 15 08:57:03 EDT 2020
build: simplify stack protector setup The old configure code was written before the stack protector was widely available and stable. On modern systems, the compiler and linker do the right thing if they support the flags at all. Downgrade the protector from 'all' to 'strong' as the latter covers any function taking the address of a stack object, providing good protection with minimal overhead. Also enable it unconditionally when available.
--- a/configure.ac
+++ b/configure.ac
@@ -80,75 +80,7 @@
enable_debug=no
fi
-# -fstack-protector
-AC_ARG_ENABLE([stack-protector],
- [AS_HELP_STRING([--disable-stack-protector],
- [Disable GCC's/libc's stack-smashing protection])],
- [case "${enableval}" in
- yes) enable_ssp=yes ;;
- no) enable_ssp=no ;;
- *) AC_MSG_ERROR([invalid value ${enableval} for --disable-stack-protector]) ;;
- esac],
- [enable_ssp=yes])
-
-if test x"$enable_ssp" = x"yes" && test x"$GCC" != x"yes"; then
- AC_MSG_NOTICE([Disabling stack-smashing protection because compiler is not GCC])
- enable_ssp=no
-fi
-
-if test x"$enable_ssp" = x"yes"; then
- # Check for broken ssp in libc: http://www.avahi.org/ticket/105
- # libc's brokenness will get in the way regardless of whether -lssp is
- # provided, but provide it anyway (otherwise non-libc ssp would wrongly
- # break here)
-
- # Get -lssp if it exists
- GCC_STACK_PROTECT_LIB
-
- AC_MSG_CHECKING([whether stack-smashing protection is available])
- ssp_old_cflags="$CFLAGS"
- ssp_old_ldflags="$LDFLAGS"
- CFLAGS="$CFLAGS -Werror -fstack-protector-all -fPIC"
- LDFLAGS="$LDFLAGS -Wl,-z,defs"
- cat confdefs.h > conftest.c
- cat >>conftest.c <<_ACEOF
-void test_broken_ssp(c)
- const char *c;
-{
- char arr[[123]], *p; /* beware of possible double-braces if copying this */
- for (p = arr; *c; ++p) {
- *p = *c;
- ++c;
- }
-}
-_ACEOF
- rm -f conftest.o
-
- if $CC -c $CFLAGS $CPPFLAGS -o conftest.o conftest.c >/dev/null 2>&1; then
- AC_MSG_RESULT([yes])
- AC_MSG_CHECKING([whether stack-smashing protection is buggy])
- if $CC -o conftest.so $LDFLAGS -shared conftest.o $LIBS >/dev/null 2>&1; then
- AC_MSG_RESULT([no])
- else
- AC_MSG_RESULT([yes])
- enable_ssp=no
- fi
- else
- AC_MSG_RESULT([no])
- fi
-
- rm -f conftest.c conftest.o conftest.so
-
- CFLAGS="$ssp_old_cflags"
- LDFLAGS="$ssp_old_ldflags"
-fi
-
-if test x"$enable_ssp" = x"yes"; then
- # Do this the long way so we don't call GCC_STACK_PROTECT_LIB twice
- GCC_STACK_PROTECT_CC
-
- # XXX: Update the enable_ssp value now for output later?
-fi
+AX_APPEND_COMPILE_FLAGS([-fstack-protector-strong])
dnl Extra CFLAGS if we have gcc
if test "$GCC" = "yes"; then
--- a/m4/gcc_stack_protect.m4
+++ /dev/null
@@ -1,99 +1,0 @@
-dnl
-dnl Useful macros for autoconf to check for ssp-patched gcc
-dnl 1.0 - September 2003 - Tiago Sousa <mirage@kaotik.org>
-dnl 1.1 - August 2006 - Ted Percival <ted@midg3t.net>
-dnl * Stricter language checking (C or C++)
-dnl * Adds GCC_STACK_PROTECT_LIB to add -lssp to LDFLAGS as necessary
-dnl * Caches all results
-dnl * Uses macros to ensure correct ouput in quiet/silent mode
-dnl 1.2 - April 2007 - Ted Percival <ted@midg3t.net>
-dnl * Added GCC_STACK_PROTECTOR macro for simpler (one-line) invocation
-dnl * GCC_STACK_PROTECT_LIB now adds -lssp to LIBS rather than LDFLAGS
-dnl
-dnl About ssp:
-dnl GCC extension for protecting applications from stack-smashing attacks
-dnl http://www.research.ibm.com/trl/projects/security/ssp/
-dnl
-dnl Usage:
-dnl Most people will simply call GCC_STACK_PROTECTOR.
-dnl If you only use one of C or C++, you can save time by only calling the
-dnl macro appropriate for that language. In that case you should also call
-dnl GCC_STACK_PROTECT_LIB first.
-dnl
-dnl GCC_STACK_PROTECTOR
-dnl Tries to turn on stack protection for C and C++ by calling the following
-dnl three macros with the right languages.
-dnl
-dnl GCC_STACK_PROTECT_CC
-dnl checks -fstack-protector with the C compiler, if it exists then updates
-dnl CFLAGS and defines ENABLE_SSP_CC
-dnl
-dnl GCC_STACK_PROTECT_CXX
-dnl checks -fstack-protector with the C++ compiler, if it exists then updates
-dnl CXXFLAGS and defines ENABLE_SSP_CXX
-dnl
-dnl GCC_STACK_PROTECT_LIB
-dnl adds -lssp to LIBS if it is available
-dnl ssp is usually provided as part of libc, but was previously a separate lib
-dnl It does not hurt to add -lssp even if libc provides SSP - in that case
-dnl libssp will simply be ignored.
-dnl
-
-AC_DEFUN([GCC_STACK_PROTECT_LIB],[
- AC_CACHE_CHECK([whether libssp exists], ssp_cv_lib,
- [ssp_old_libs="$LIBS"
- LIBS="$LIBS -lssp"
- AC_TRY_LINK(,, ssp_cv_lib=yes, ssp_cv_lib=no)
- LIBS="$ssp_old_libs"
- ])
- if test $ssp_cv_lib = yes; then
- LIBS="$LIBS -lssp"
- fi
-])
-
-AC_DEFUN([GCC_STACK_PROTECT_CC],[
- AC_LANG_ASSERT(C)
- if test "X$CC" != "X"; then
- AC_CACHE_CHECK([whether ${CC} accepts -fstack-protector],
- ssp_cv_cc,
- [ssp_old_cflags="$CFLAGS"
- CFLAGS="$CFLAGS -fstack-protector -Werror"
- AC_TRY_COMPILE(,, ssp_cv_cc=yes, ssp_cv_cc=no)
- CFLAGS="$ssp_old_cflags"
- ])
- if test $ssp_cv_cc = yes; then
- CFLAGS="$CFLAGS -fstack-protector"
- AC_DEFINE([ENABLE_SSP_CC], 1, [Define if SSP C support is enabled.])
- fi
- fi
-])
-
-AC_DEFUN([GCC_STACK_PROTECT_CXX],[
- AC_LANG_ASSERT(C++)
- if test "X$CXX" != "X"; then
- AC_CACHE_CHECK([whether ${CXX} accepts -fstack-protector],
- ssp_cv_cxx,
- [ssp_old_cxxflags="$CXXFLAGS"
- CXXFLAGS="$CXXFLAGS -fstack-protector -Werror"
- AC_TRY_COMPILE(,, ssp_cv_cxx=yes, ssp_cv_cxx=no)
- CXXFLAGS="$ssp_old_cxxflags"
- ])
- if test $ssp_cv_cxx = yes; then
- CXXFLAGS="$CXXFLAGS -fstack-protector"
- AC_DEFINE([ENABLE_SSP_CXX], 1, [Define if SSP C++ support is enabled.])
- fi
- fi
-])
-
-AC_DEFUN([GCC_STACK_PROTECTOR],[
- GCC_STACK_PROTECT_LIB
-
- AC_LANG_PUSH([C])
- GCC_STACK_PROTECT_CC
- AC_LANG_POP([C])
-
- AC_LANG_PUSH([C++])
- GCC_STACK_PROTECT_CXX
- AC_LANG_POP([C++])
-])
-