From: Thomas Schwinge <tschwinge@gnu.org>
To: grub-devel@gnu.org
Subject: Re: Stack protection via GCC's `-fstack-protector'
Date: Fri, 15 Dec 2006 20:36:09 +0100 [thread overview]
Message-ID: <20061215193609.GV19641@fencepost> (raw)
In-Reply-To: <20061108214054.GU32338@fencepost>
[-- Attachment #1: Type: text/plain, Size: 3760 bytes --]
Hello!
On Wed, Nov 08, 2006 at 10:40:54PM +0100, I wrote:
> For some time, GCC now offers the following feature:
>
> info Gcc
> #v+
> `-fstack-protector'
> Emit extra code to check for buffer overflows, such as stack
> smashing attacks. This is done by adding a guard variable to
> functions with vulnerable objects. This includes functions that
> call alloca, and functions with buffers larger than 8 bytes. The
> guards are initialized when a function is entered and then checked
> when the function exits. If a guard check fails, an error message
> is printed and the program exits.
> #v-
>
> I now happen to be running a GCC 4.1 installation which has that one
> enabled by default. Unfortunately, building GNU Mach and GRUB2 (didn't
> check GRUB legacy) is affected by that:
To completely support this feature in kernel-like environments, work on
GCC itself is needed, see
<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29838>, so for the mean time
I created the following patch to be able to continue building GRUB2 on
systems that have `-fstack-protector' enabled by default. (This patch is
equal to what we've been using in GNU Mach for some time now.)
2006-12-15 Thomas Schwinge <tschwinge@gnu.org>
* aclocal.m4 (grub_CHECK_STACK_PROTECTOR): New definition.
* configure.ac: Use it for testing the HOST and TARGET compilers.
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/grub/grub2/aclocal.m4,v
retrieving revision 1.5
diff -u -p -r1.5 aclocal.m4
--- aclocal.m4 13 Aug 2005 18:44:14 -0000 1.5
+++ aclocal.m4 15 Dec 2006 19:18:18 -0000
@@ -343,3 +343,23 @@ dnl So use regparm 2 until a better test
[Catch gcc bug])
fi
])
+\f
+dnl Check if the C compiler supports `-fstack-protector'.
+dnl Written by Thomas Schwinge.
+AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
+[# Smashing stack protector.
+ssp_possible=yes]
+AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
+# Is this a reliable test case?
+AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
+[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
+# `ac_compile' like this correct, after all?
+if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
+ AC_MSG_RESULT([yes])
+ [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
+ rm -f conftest.s
+else
+ ssp_possible=no]
+ AC_MSG_RESULT([no])
+[fi]
+])
Index: configure.ac
===================================================================
RCS file: /cvsroot/grub/grub2/configure.ac,v
retrieving revision 1.35
diff -u -p -r1.35 configure.ac
--- configure.ac 13 Dec 2006 22:30:19 -0000 1.35
+++ configure.ac 15 Dec 2006 19:18:18 -0000
@@ -149,6 +149,19 @@ fi
AC_CHECK_FUNCS(posix_memalign memalign)
#
+# Compiler features.
+#
+
+# Smashing stack protector.
+grub_CHECK_STACK_PROTECTOR
+[# Need that, because some distributions ship compilers that include
+# `-fstack-protector' in the default specs.
+if [ x"$ssp_possible" = xyes ]; then
+ CFLAGS=$CFLAGS\ -fno-stack-protector
+fi]
+
+
+#
# Check for target programs.
#
@@ -225,6 +238,18 @@ if test "x$target_m32" = x1; then
TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
fi
+#
+# Compiler features.
+#
+
+# Smashing stack protector.
+grub_CHECK_STACK_PROTECTOR
+[# Need that, because some distributions ship compilers that include
+# `-fstack-protector' in the default specs.
+if [ x"$ssp_possible" = xyes ]; then
+ TARGET_CFLAGS=$TARGET_CFLAGS\ -fno-stack-protector
+fi]
+
AC_SUBST(TARGET_CFLAGS)
AC_SUBST(TARGET_CPPFLAGS)
AC_SUBST(TARGET_LDFLAGS)
Regards,
Thomas
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2006-12-15 19:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-08 21:40 Stack protection via GCC's `-fstack-protector' Thomas Schwinge
2006-11-08 22:14 ` Samuel Thibault
2006-11-08 22:36 ` Thomas Schwinge
2006-11-13 18:29 ` Thomas Schwinge
2006-11-13 18:44 ` Samuel Thibault
2006-11-08 22:36 ` Stefan Reinauer
2006-11-08 22:46 ` Samuel Thibault
2006-12-15 19:36 ` Thomas Schwinge [this message]
2007-02-03 11:40 ` Thomas Schwinge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061215193609.GV19641@fencepost \
--to=tschwinge@gnu.org \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.