Skip to content

Commit ab0d3e5

Browse files
committed
add windows-specific hardening options
This enables DEP and ALSR capabilities. Stack protection is enabled optionally, there are some extra linking steps required that make it difficult to enable by default.
1 parent 347c03d commit ab0d3e5

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

configure.ac

+23-8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ AC_ARG_ENABLE([hardening],
104104
[Disable options to frustrate memory corruption exploits])],
105105
[], [enable_hardening=yes])
106106

107+
AC_ARG_ENABLE([windows-ssp],
108+
[AS_HELP_STRING([--enable-windows-ssp],
109+
[Enable building the stack smashing protection on
110+
Windows. This currently distributing libssp-0.dll.])])
111+
107112
AC_DEFUN([CHECK_CFLAG], [
108113
AC_LANG_ASSERT(C)
109114
AC_MSG_CHECKING([if $saved_CC supports "$1"])
@@ -148,16 +153,26 @@ AS_IF([test "x$enable_hardening" = "xyes"], [
148153
# Enable read only relocations
149154
CHECK_LDFLAG([[-Wl,-z,relro]])
150155
CHECK_LDFLAG([[-Wl,-z,now]])
151-
])
152156
153-
# Use stack-protector-strong if available; if not, fallback to
154-
# stack-protector-all which is considered to be overkill
155-
AS_IF([test "x$enable_hardening" = "xyes" -a "x$HOST_OS" != "xwin"], [
156-
CHECK_CFLAG([[-fstack-protector-strong]],
157-
CHECK_CFLAG([[-fstack-protector-all]],
158-
AC_MSG_WARN([compiler does not appear to support stack protection])
157+
# Windows security flags
158+
AS_IF([test "x$HOST_OS" = "xwin"], [
159+
CHECK_LDFLAG([[-Wl,--nxcompat]])
160+
CHECK_LDFLAG([[-Wl,--dynamicbase]])
161+
CHECK_LDFLAG([[-Wl,--high-entropy-va]])
162+
])
163+
164+
# Use stack-protector-strong if available; if not, fallback to
165+
# stack-protector-all which is considered to be overkill
166+
AS_IF([test "x$enable_windows_ssp" = "xyes" -o "x$HOST_OS" != "xwin"], [
167+
CHECK_CFLAG([[-fstack-protector-strong]],
168+
CHECK_CFLAG([[-fstack-protector-all]],
169+
AC_MSG_WARN([compiler does not appear to support stack protection])
170+
)
159171
)
160-
)
172+
AS_IF([test "x$HOST_OS" = "xwin"], [
173+
AC_SEARCH_LIBS([__stack_chk_guard],[ssp])
174+
])
175+
])
161176
])
162177

163178

0 commit comments

Comments
 (0)