Skip to content

Commit b536813

Browse files
committed
build: add -fstack-clash-protection to hardening flags
This option causes the compiler to insert probes whenever stack space is allocated statically or dynamically to reliably detect stack overflows and thus mitigate the attack vector that relies on jumping over a stack guard page as provided by the operating system. This option is now enabled by default in Ubuntu GCC as of 19.10. Available in GCC 8 and Clang 11.
1 parent 076183b commit b536813

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,13 @@ if test x$use_hardening != xno; then
786786
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
787787

788788
AX_CHECK_COMPILE_FLAG([-fcf-protection=full],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fcf-protection=full"])
789+
790+
dnl stack-clash-protection does not work properly when building for Windows.
791+
dnl We use the test case from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
792+
dnl to determine if it can be enabled.
793+
AX_CHECK_COMPILE_FLAG([-fstack-clash-protection],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-clash-protection"],[],["-O0"],
794+
[AC_LANG_SOURCE([[class D {public: unsigned char buf[32768];}; int main() {D d; return 0;}]])])
795+
789796
dnl When enable_debug is yes, all optimizations are disabled.
790797
dnl However, FORTIFY_SOURCE requires that there is some level of optimization, otherwise it does nothing and just creates a compiler warning.
791798
dnl Since FORTIFY_SOURCE is a no-op without optimizations, do not enable it when enable_debug is yes.

0 commit comments

Comments
 (0)