Skip to contentSkip to conversation

configure.ac: warn if stack-protector not allowed

PATCH Superseded Nicholas Vinson 2 participants 3 messages Jul 6, 2022 – Jul 7, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 configure.ac: warn if stack-protector not allowed

Introduce ERROR_PLATFORM_NOT_SUPPORT_SSP environment variable to treat the '--enable-stack-protector is only supported on EFI platforms' message as a warning instead of an error. If ERROR_PLATFORM_NOT_SUPPORT_SSP is set to 'no' (case-insensitive), then the message will be printed as a warning. Otherwise, it prints as an error. The default behavior is to print the message as an error.

For any wrapper build script that has some variation of:

    for p in SELECTED_GRUB_PLATFORMS; do    \
        configure --enable-stack-protector  \
            --with-platform${P} ... || die; \
    done
    make

GRUB will fail to build if SELECTED_GRUB_PLATFORMS contains a platform that does not support SSP.

Such wrapper scripts need to work-around this issue by modifying the above for-loop, so it conditionally passes '--enable-stack-protector' to configure for the proper GRUB platform(s).

However, if the above example is modified to have to conditionally pass in --enable-stack-protector, its behavior is effectively the same as the proposed change. Additionally, The list of SSP supported platforms is now in 2 places. One in the configure script and one in the build wrapper script. If the second list is not properly maintained it could mistakenly disable SSP for a platform that later gained support for it.

---
 configure.ac | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
configure.ac +11 -1
index 57fb70945..a08f3285e 100644
@@ -36,6 +36,10 @@ dnl description of the relationships between them.
 
 AC_INIT([GRUB],[2.11],[[email protected]])
 
+AS_CASE(["$ERROR_PLATFORM_NOT_SUPPORT_SSP"],
+  [n | no | nO | N | No | NO], [ERROR_PLATFORM_NOT_SUPPORT_SSP=no],
+  [ERROR_PLATFORM_NOT_SUPPORT_SSP=yes])
+
 # We don't want -g -O2 by default in CFLAGS
 : ${CFLAGS=""}
 
@@ -1342,6 +1346,7 @@ AC_ARG_ENABLE([stack-protector],
 			     [enable the stack protector]),
 	      [],
 	      [enable_stack_protector=no])
+
 if test "x$enable_stack_protector" = xno; then
   if test "x$ssp_possible" = xyes; then
     # Need that, because some distributions ship compilers that include
@@ -1349,7 +1354,12 @@ if test "x$enable_stack_protector" = xno; then
     TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
   fi
 elif test "x$platform" != xefi; then
-  AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
+  if test "$ERROR_PLATFORM_NOT_SUPPORT_SSP" = "yes"; then
+    AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
+  else
+    AC_MSG_WARN([--enable-stack-protector is only supported on EFI platforms])
+  fi
+  enable_stack_protector=no
 elif test "x$ssp_global_possible" != xyes; then
   AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -mstack-protector-guard=global)])
 else
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 22 lines · Nicholas Vinson

Introduce ERROR_PLATFORM_NOT_SUPPORT_SSP environment variable to treat the '--enable-stack-protector is only supported on EFI platforms' message as a warning instead of an error. If ERROR_PLATFORM_NOT_SUPPORT_SSP is set to 'no' (case-insensitive), then the message will be printed as a warning. Otherwise, it prints as an error. The default behavior is to print the message as an error.

For any wrapper build script that has some variation of:

    for p in SELECTED_GRUB_PLATFORMS; do    \
        configure --enable-stack-protector  \
            --with-platform${P} ... || die; \
    done
    make

GRUB will fail to build if SELECTED_GRUB_PLATFORMS contains a platform that does not support SSP.

Such wrapper scripts need to work-around this issue by modifying the above for-loop, so it conditionally passes '--enable-stack-protector' to configure for the proper GRUB platform(s).

Quoted 8 lines

However, if the above example is modified to have to conditionally pass in --enable-stack-protector, its behavior is effectively the same as the proposed change. Additionally, The list of SSP supported platforms is now in 2 places. One in the configure script and one in the build wrapper script. If the second list is not properly maintained it could mistakenly disable SSP for a platform that later gained support for it.

But one nit below...

Quoted 20 lines
---
 configure.ac | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
configure.ac +4 -0
index 57fb70945..a08f3285e 100644
@@ -36,6 +36,10 @@ dnl description of the relationships between them.
 
 AC_INIT([GRUB],[2.11],[[email protected]])
 
+AS_CASE(["$ERROR_PLATFORM_NOT_SUPPORT_SSP"],
+  [n | no | nO | N | No | NO], [ERROR_PLATFORM_NOT_SUPPORT_SSP=no],
+  [ERROR_PLATFORM_NOT_SUPPORT_SSP=yes])
+
 # We don't want -g -O2 by default in CFLAGS
 : ${CFLAGS=""}
 

configure.ac AC_ARG_ENABLE([stack-protector], · line 1349

Quoted 4 lines
configure.ac +1 -0
@@ -1342,6 +1346,7 @@ AC_ARG_ENABLE([stack-protector],
 			     [enable the stack protector]),
 	      [],
 	      [enable_stack_protector=no])
+

I think this change can be dropped...

Quoted 7 lines
configure.ac +0 -0
 if test "x$enable_stack_protector" = xno; then
   if test "x$ssp_possible" = xyes; then
     # Need that, because some distributions ship compilers that include
@@ -1349,7 +1354,12 @@ if test "x$enable_stack_protector" = xno; then
     TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
   fi
 elif test "x$platform" != xefi; then

configure.ac if test "x$enable_stack_protector" = xno; then · line 1365

Quoted 10 lines
configure.ac +6 -1
-  AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
+  if test "$ERROR_PLATFORM_NOT_SUPPORT_SSP" = "yes"; then
+    AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
+  else
+    AC_MSG_WARN([--enable-stack-protector is only supported on EFI platforms])
+  fi
+  enable_stack_protector=no
 elif test "x$ssp_global_possible" != xyes; then
   AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -mstack-protector-guard=global)])
 else

Daniel

#2 lore raw
Quoted 55 lines · Daniel Kiper
Quoted 22 lines · Nicholas Vinson

Introduce ERROR_PLATFORM_NOT_SUPPORT_SSP environment variable to treat the '--enable-stack-protector is only supported on EFI platforms' message as a warning instead of an error. If ERROR_PLATFORM_NOT_SUPPORT_SSP is set to 'no' (case-insensitive), then the message will be printed as a warning. Otherwise, it prints as an error. The default behavior is to print the message as an error.

For any wrapper build script that has some variation of:

     for p in SELECTED_GRUB_PLATFORMS; do    \
         configure --enable-stack-protector  \
             --with-platform${P} ... || die; \
     done
     make

GRUB will fail to build if SELECTED_GRUB_PLATFORMS contains a platform that does not support SSP.

Such wrapper scripts need to work-around this issue by modifying the above for-loop, so it conditionally passes '--enable-stack-protector' to configure for the proper GRUB platform(s).

Quoted 8 lines

However, if the above example is modified to have to conditionally pass in --enable-stack-protector, its behavior is effectively the same as the proposed change. Additionally, The list of SSP supported platforms is now in 2 places. One in the configure script and one in the build wrapper script. If the second list is not properly maintained it could mistakenly disable SSP for a platform that later gained support for it.

But one nit below...

Quoted 19 lines
---
  configure.ac | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)
configure.ac +4 -0
index 57fb70945..a08f3285e 100644
@@ -36,6 +36,10 @@ dnl description of the relationships between them.
 
  AC_INIT([GRUB],[2.11],[[email protected]])
 
+AS_CASE(["$ERROR_PLATFORM_NOT_SUPPORT_SSP"],
+  [n | no | nO | N | No | NO], [ERROR_PLATFORM_NOT_SUPPORT_SSP=no],
+  [ERROR_PLATFORM_NOT_SUPPORT_SSP=yes])
+
  # We don't want -g -O2 by default in CFLAGS
  : ${CFLAGS=""}
 
Quoted 7 lines

configure.ac AC_ARG_ENABLE([stack-protector], · line 1349

Quoted 5 lines
configure.ac +1 -0
@@ -1342,6 +1346,7 @@ AC_ARG_ENABLE([stack-protector],
  			     [enable the stack protector]),
  	      [],
  	      [enable_stack_protector=no])
+

I think this change can be dropped...

Agreed. It's an errant white space only change. Unless someone says otherwise, I'll regenerate the request with this change removed.

Thanks,
Nicholas Vinson

Quoted 20 lines
Quoted 8 lines
configure.ac +0 -0
  if test "x$enable_stack_protector" = xno; then
    if test "x$ssp_possible" = xyes; then
      # Need that, because some distributions ship compilers that include
@@ -1349,7 +1354,12 @@ if test "x$enable_stack_protector" = xno; then
      TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
    fi
  elif test "x$platform" != xefi; then

configure.ac if test "x$enable_stack_protector" = xno; then · line 1365

Quoted 10 lines
configure.ac +6 -1
-  AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
+  if test "$ERROR_PLATFORM_NOT_SUPPORT_SSP" = "yes"; then
+    AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
+  else
+    AC_MSG_WARN([--enable-stack-protector is only supported on EFI platforms])
+  fi
+  enable_stack_protector=no
  elif test "x$ssp_global_possible" != xyes; then
    AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -mstack-protector-guard=global)])
  else

Daniel