[08/15] Add a hidden __stack_chk_fail_local alias to libc.so.

Message ID 20161219111528.14969-9-nix@esperi.org.uk
State Committed
Headers

Commit Message

Nix Dec. 19, 2016, 11:15 a.m. UTC
  From: Nick Alcock <nick.alcock@oracle.com>

This is required by the next commit, which routes all
__stack_chk_fail() calls in libc.so via this symbol to avoid
the PLT.

Also stop all the variants of __stack_chk_fail from being stack-
protected: this makes no sense and risks recursion.

v5: Better explanation.  Add no-stack-protection of
    __stack_chk_fail_local etc.
v6: Rework as suggested by Andreas: make a shared-only version of
    stack_chk_fail_local.c rather than linking libc_nonshared into
    libc.
v10: Drop libc-stack_chk_fail_local.c: just use a strong_alias instead.
     (Thanks to Florian Weimer.)

	* debug/stack_chk_fail.c (__stack_chk_fail): Add strong_alias to
	__stack_chk_fail_local.
	* debug/Makefile (CFLAGS-stack_chk_fail.c): Use $(no-stack-protector).
	(CFLAGS-stack_chk_fail_local.c): Likewise.
---
 debug/Makefile         | 6 ++++++
 debug/stack_chk_fail.c | 2 ++
 2 files changed, 8 insertions(+)
  

Patch

diff --git a/debug/Makefile b/debug/Makefile
index 6b5f31e..2f506af 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -52,6 +52,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)
diff --git a/debug/stack_chk_fail.c b/debug/stack_chk_fail.c
index 4d0796f..5db0886 100644
--- a/debug/stack_chk_fail.c
+++ b/debug/stack_chk_fail.c
@@ -27,3 +27,5 @@  __stack_chk_fail (void)
 {
   __fortify_fail ("stack smashing detected");
 }
+
+strong_alias (__stack_chk_fail, __stack_chk_fail_local)