From patchwork Thu Dec 15 14:29:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nix X-Patchwork-Id: 18480 Received: (qmail 50407 invoked by alias); 15 Dec 2016 14:29:20 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 49955 invoked by uid 89); 15 Dec 2016 14:29:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=overlooked X-HELO: mail.esperi.org.uk From: Nix To: Florian Weimer Cc: libc-alpha@sourceware.org, Adhemerval Zanella Subject: Re: [PATCH 08/12] De-PLTize __stack_chk_fail internal calls within libc.so. References: <20161128123228.30856-1-nix@esperi.org.uk> <20161128123228.30856-9-nix@esperi.org.uk> <87y3zhjn1s.fsf@esperi.org.uk> <78b1f109-91e5-4150-4c00-15a86aacb2f7@redhat.com> Date: Thu, 15 Dec 2016 14:29:00 +0000 In-Reply-To: <78b1f109-91e5-4150-4c00-15a86aacb2f7@redhat.com> (Florian Weimer's message of "Thu, 15 Dec 2016 15:21:18 +0100") Message-ID: <87poktjmfn.fsf@esperi.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.94 (gnu/linux) MIME-Version: 1.0 X-DCC--Metrics: spindle 1480; Body=3 Fuz1=3 Fuz2=3 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. > 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.) 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