This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 08/12] De-PLTize __stack_chk_fail internal calls within libc.so.


On 12/15/2016 03:29 PM, Nix wrote:
On 15 Dec 2016, Florian Weimer told this:

On 12/15/2016 03:15 PM, Nix wrote:

Possible fix, untested:

diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 36908b5..0679354 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -7,5 +7,7 @@ asm ("memcpy = __GI_memcpy");

 /* -fstack-protector generates calls to __stack_chk_fail, which need
    similar adjustments to avoid going through the PLT.  */
+#if defined __SSP__ || defined __SSP_ALL__ || defined __SSP_STRONG__
 asm ("__stack_chk_fail = __stack_chk_fail_local");
 #endif
+#endif

The condition looks rather brittle.  What if GCC grows an -fstack-protector-light switch and __SSP_LIGHT__ macro?

We'd need to change configure.ac before that would have an effect in any
case... but it does seem likely that changing this too would be
overlooked.

Right.

I wonder if it's better to add something to $(no-stack-protector) and use that in the conditional.

That was my other option, but the total absence of anything in
configure.ac passing -D made me think twice.

Something like this? (even more untested than the last one, if
possible -- but adds a new possibility: we can now differentiate between
"glibc built without stack protector" and "glibc built with stack
protector but this file doesn't have it" without relying on GCC
predefined macros. The __WITH_ naming scheme is completely arbitrary
and I can change it to anything you prefer.)

WITH_STACK_PROTECTOR (without the leading underscores) looks okay to me because it's only used at build time. Or you could call it STACK_PROTECTOR_LEVEL, to match the other variable.

diff --git a/configure.ac b/configure.ac
index 2396c1f..8bb8c2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -638,18 +638,18 @@ LIBC_TRY_CC_OPTION([$CFLAGS $CPPFLAGS -Werror -fstack-protector-all],
 stack_protector=
 no_stack_protector=
 if test "$libc_cv_ssp" = yes; then
-  no_stack_protector="-fno-stack-protector"
+  no_stack_protector="-fno-stack-protector -D__WITH_STACK_PROTECTOR=0"
   AC_DEFINE(HAVE_CC_NO_STACK_PROTECTOR)
 fi

 if test "$enable_stack_protector" = yes && test "$libc_cv_ssp" = yes; then
-  stack_protector="-fstack-protector"
+  stack_protector="-fstack-protector -D__WITH_STACK_PROTECTOR=1"
   AC_DEFINE(STACK_PROTECTOR_LEVEL, 1)
 elif test "$enable_stack_protector" = all && test "$libc_cv_ssp_all" = yes; then
-  stack_protector="-fstack-protector-all"
+  stack_protector="-fstack-protector-all -D__WITH_STACK_PROTECTOR=2"
   AC_DEFINE(STACK_PROTECTOR_LEVEL, 2)
 elif test "$enable_stack_protector" = strong && test "$libc_cv_ssp_strong" = yes; then
-  stack_protector="-fstack-protector-strong"
+  stack_protector="-fstack-protector-strong -D__WITH_STACK_PROTECTOR=3"
   AC_DEFINE(STACK_PROTECTOR_LEVEL, 3)
 fi
 AC_SUBST(libc_cv_ssp)
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 36908b5..12b4fe7 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -7,5 +7,7 @@ asm ("memcpy = __GI_memcpy");

 /* -fstack-protector generates calls to __stack_chk_fail, which need
    similar adjustments to avoid going through the PLT.  */
+#if defined __WITH_STACK_PROTECTOR && __WITH_STACK_PROTECTOR > 0
 asm ("__stack_chk_fail = __stack_chk_fail_local");
 #endif
+#endif

The new #if/#endif need to be indented.

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]