]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
PLT avoidance for __stack_chk_fail [BZ #7065]
authorNick Alcock <nick.alcock@oracle.com>
Mon, 26 Dec 2016 09:08:57 +0000 (10:08 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 26 Dec 2016 09:11:05 +0000 (10:11 +0100)
Add a hidden __stack_chk_fail_local alias to libc.so,
and make sure that on targets which use __stack_chk_fail,
this does not introduce a local PLT reference into libc.so.

ChangeLog
debug/Makefile
debug/stack_chk_fail.c
sysdeps/generic/symbol-hacks.h

index 5e3e64a3da22874edd17fc8f04fb924edad8ea4e..10d5a377183aabbd0dd557cb696829a8b3125c38 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2016-12-26  Nick Alcock  <nick.alcock@oracle.com>
+           Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+           Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #7065]
+       PLT avoidance for __stack_chk_fail*.
+       * debug/Makefile (CFLAGS-stack_chk_fail.c)
+       (CFLAGS-stack_chk_fail_local.c): Build without stack protector.
+       * debug/stack_chk_fail.c (__stack_chk_fail): Add
+       __stack_chk_fail_local alias.
+       * sysdeps/generic/symbol-hacks.h [IS_IN (libc)]
+       (__stack_chk_fail): Turn into hidden reference to
+       __stack_chk_fail_local.
+
 2016-12-26  Nick Alcock  <nick.alcock@oracle.com>
 
        [BZ #7065]
index 84d3f92c0d8e44f9648ca05dd7360e5b8421e590..ed7c39793b98247c9744c8a5abb0d58b4301e4be 100644 (file)
@@ -53,6 +53,12 @@ routines  = backtrace backtracesyms backtracesymsfd noophooks \
            $(static-only-routines)
 static-only-routines := warning-nop stack_chk_fail_local
 
+# Building the stack-protector failure routines with stack protection
+# makes no sense.
+
+CFLAGS-stack_chk_fail.c = $(no-stack-protector)
+CFLAGS-stack_chk_fail_local.c = $(no-stack-protector)
+
 CFLAGS-backtrace.c = -fno-omit-frame-pointer
 CFLAGS-sprintf_chk.c = $(libio-mtsafe)
 CFLAGS-snprintf_chk.c = $(libio-mtsafe)
index 4d0796f78c398b3eac739716a5ba0e632704f6ac..5db0886170a8afeb31863d9d135cf904fb99b26f 100644 (file)
@@ -27,3 +27,5 @@ __stack_chk_fail (void)
 {
   __fortify_fail ("stack smashing detected");
 }
+
+strong_alias (__stack_chk_fail, __stack_chk_fail_local)
index ce576c9fd26d9f4fd9f9b24fb438c23c3c44c775..d614c099c9f91447a331ed3a90155960cca597cd 100644 (file)
@@ -4,4 +4,16 @@
 asm ("memmove = __GI_memmove");
 asm ("memset = __GI_memset");
 asm ("memcpy = __GI_memcpy");
+
+/* Some targets do not use __stack_chk_fail_local.  In libc.so,
+   redirect __stack_chk_fail to a hidden reference
+   __stack_chk_fail_local, to avoid the PLT reference.
+   __stack_chk_fail itself is a global symbol, exported from libc.so,
+   and cannot be made hidden.  */
+
+# if IS_IN (libc) && defined SHARED && \
+  defined STACK_PROTECTOR_LEVEL && STACK_PROTECTOR_LEVEL > 0
+asm (".hidden __stack_chk_fail_local\n"
+     "__stack_chk_fail = __stack_chk_fail_local");
+# endif
 #endif