Bug 620058 - Add a --enable-hardening flag, which compiles with -fstack-protector-strong on GCC and Clang draft
authorAlex Gaynor <agaynor@mozilla.com>
Wed, 12 Apr 2017 13:58:22 -0400
changeset 568055 91cd2f0c8b3c962bd3c005a8b7c5c16464f25f29
parent 567802 f229b7e5d91eb70d23d3e31db7caff9d69a2ef04
child 625809 f7b9f94f768dbca4e6c6579432d64ddc683a8994
push id55745
push userbmo:agaynor@mozilla.com
push dateTue, 25 Apr 2017 18:40:11 +0000
bugs620058
milestone55.0a1
Bug 620058 - Add a --enable-hardening flag, which compiles with -fstack-protector-strong on GCC and Clang This flag enables the stack-cookie exploit mitigation for all functions which manipulate stack-based buffers, providing better protections than -fstack-protector, at considerably lower performance overhead than -fstack-protector-all. r=froydnj MozReview-Commit-ID: 7ZNAHHAf376
build/moz.configure/toolchain.configure
old-configure.in
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -969,8 +969,21 @@ set_config('VISIBILITY_FLAGS', visibilit
 
 # We only want to include windows.configure when we are compiling on
 # Windows, for Windows.
 @depends(target, host)
 def is_windows(target, host):
     return host.kernel == 'WINNT' and target.kernel == 'WINNT'
 
 include('windows.configure', when=is_windows)
+
+# Security Hardening
+# ==============================================================
+
+option('--enable-hardening', env='MOZ_SECURITY_HARDENING',
+       help='Enables security hardening compiler options')
+
+@depends('--enable-hardening', c_compiler)
+def security_hardening_cflags(value, c_compiler):
+    if value and c_compiler.type in ['gcc', 'clang']:
+        return '-fstack-protector-strong'
+
+add_old_configure_assignment('HARDENING_CFLAGS', security_hardening_cflags)
--- a/old-configure.in
+++ b/old-configure.in
@@ -548,16 +548,21 @@ fi
 if test -n "${CLANG_CXX}${CLANG_CL}"; then
     _WARNINGS_CXXFLAGS="-Qunused-arguments ${_WARNINGS_CXXFLAGS}"
 fi
 
 if test -n "$COMPILE_ENVIRONMENT"; then
    MOZ_CONFIG_SANITIZE
 fi
 
+# Add the hardening flags from moz.configure
+CFLAGS="$CFLAGS $HARDENING_CFLAGS"
+CPPFLAGS="$CPPFLAGS $HARDENING_CFLAGS"
+CXXFLAGS="$CXXFLAGS $HARDENING_CFLAGS"
+
 dnl ========================================================
 dnl GNU specific defaults
 dnl ========================================================
 if test "$GNU_CC"; then
     MMX_FLAGS="-mmmx"
     SSE_FLAGS="-msse"
     SSE2_FLAGS="-msse2"
     SSSE3_FLAGS="-mssse3"