From patchwork Sun Feb 28 16:41:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nix X-Patchwork-Id: 11124 Received: (qmail 83175 invoked by alias); 28 Feb 2016 16:41:43 -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 82990 invoked by uid 89); 28 Feb 2016 16:41:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=UD:ro, $cflags, $CC, $cc X-HELO: mail.esperi.org.uk From: Nix To: libc-alpha@sourceware.org Subject: [PATCH 03/16] Do not stack-protect ifunc resolvers. Date: Sun, 28 Feb 2016 16:41:22 +0000 Message-Id: <1456677695-29778-4-git-send-email-nix@esperi.org.uk> In-Reply-To: <1456677695-29778-1-git-send-email-nix@esperi.org.uk> References: <1456677695-29778-1-git-send-email-nix@esperi.org.uk> X-DCC-URT-Metrics: spindle 1060; Body=1 Fuz1=1 Fuz2=1 From: Nick Alcock When dynamically linking, ifunc resolvers are called before TLS is initialized, so they cannot be safely stack-protected. We avoid disabling stack-protection on large numbers of files by depending on the availability of __attribute__ ((__optimize__ ("-fno-stack-protector"))), and turning it off just for the resolvers themselves. (We provide the attribute even when statically linking, because we will later use it elsewhere too.) v4: New. --- config.h.in | 4 ++++ configure.ac | 15 +++++++++++++++ elf/ifuncdep2.c | 3 +++ elf/ifuncmain6pie.c | 1 + elf/ifuncmain7.c | 1 + elf/ifuncmod1.c | 3 +++ elf/ifuncmod5.c | 3 +++ include/libc-symbols.h | 19 +++++++++++++++++-- nptl/pt-fork.c | 1 + nptl/pt-longjmp.c | 1 + nptl/pt-system.c | 1 + nptl/pt-vfork.c | 1 + rt/clock-compat.c | 4 +++- sysdeps/generic/ifunc-sel.h | 2 ++ sysdeps/nacl/nacl_interface_query.c | 1 + sysdeps/powerpc/ifunc-sel.h | 2 ++ sysdeps/unix/make-syscalls.sh | 1 + sysdeps/unix/sysv/linux/powerpc/gettimeofday.c | 1 + sysdeps/unix/sysv/linux/powerpc/time.c | 1 + sysdeps/unix/sysv/linux/x86/gettimeofday.c | 1 + sysdeps/unix/sysv/linux/x86/time.c | 1 + sysdeps/unix/sysv/linux/x86_64/x32/getcpu.c | 1 + sysdeps/x86_64/ifuncmod8.c | 1 + 23 files changed, 66 insertions(+), 3 deletions(-) diff --git a/config.h.in b/config.h.in index ec9c8bc..7bbc148 100644 --- a/config.h.in +++ b/config.h.in @@ -43,6 +43,10 @@ /* Define if compiler accepts -ftree-loop-distribute-patterns. */ #undef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL +/* Define if compiler accepts -fno-stack-protector in an + __attribute__((__optimize__)). */ +#undef HAVE_CC_NO_STACK_PROTECTOR + /* Define if the regparm attribute shall be used for local functions (gcc on ix86 only). */ #undef USE_REGPARMS diff --git a/configure.ac b/configure.ac index 7b81049..a920f89 100644 --- a/configure.ac +++ b/configure.ac @@ -632,10 +632,25 @@ LIBC_TRY_CC_OPTION([$CFLAGS $CPPFLAGS -Werror -fstack-protector-all], [libc_cv_ssp_all=no]) ]) +AC_CACHE_CHECK(if $CC accepts -fno-stack-protector with \ +__attribute__ ((__optimize__)), libc_cv_cc_no_stack_protector, [dnl +cat > conftest.c <'; \\ echo 'extern void *${strong}_ifunc (void) __asm ("${strong}");'; \\ echo 'void *'; \\ + echo 'inhibit_stack_protector'; \\ echo '${strong}_ifunc (void)'; \\ echo '{'; \\ echo ' PREPARE_VERSION_KNOWN (symver, ${vdso_symver});'; \\ diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c index 25a4e7c..a8b6cfa 100644 --- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c @@ -33,6 +33,7 @@ __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) } void * +inhibit_stack_protector gettimeofday_ifunc (void) { PREPARE_VERSION (linux2615, "LINUX_2.6.15", 123718565); diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c index 7973419..4b89b38 100644 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ b/sysdeps/unix/sysv/linux/powerpc/time.c @@ -43,6 +43,7 @@ time_syscall (time_t *t) } void * +inhibit_stack_protector time_ifunc (void) { PREPARE_VERSION (linux2615, "LINUX_2.6.15", 123718565); diff --git a/sysdeps/unix/sysv/linux/x86/gettimeofday.c b/sysdeps/unix/sysv/linux/x86/gettimeofday.c index 36f7c26..e05ad53 100644 --- a/sysdeps/unix/sysv/linux/x86/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/x86/gettimeofday.c @@ -32,6 +32,7 @@ __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday"); void * +inhibit_stack_protector gettimeofday_ifunc (void) { PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c index f5f7f91..c5bd8dc 100644 --- a/sysdeps/unix/sysv/linux/x86/time.c +++ b/sysdeps/unix/sysv/linux/x86/time.c @@ -33,6 +33,7 @@ __time_syscall (time_t *t) void *time_ifunc (void) __asm__ ("time"); void * +inhibit_stack_protector time_ifunc (void) { PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/getcpu.c b/sysdeps/unix/sysv/linux/x86_64/x32/getcpu.c index cbac4b3..8436f9d 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/getcpu.c +++ b/sysdeps/unix/sysv/linux/x86_64/x32/getcpu.c @@ -21,6 +21,7 @@ void *getcpu_ifunc (void) __asm__ ("__getcpu"); void * +inhibit_stack_protector getcpu_ifunc (void) { PREPARE_VERSION (linux26, "LINUX_2.6", 61765110); diff --git a/sysdeps/x86_64/ifuncmod8.c b/sysdeps/x86_64/ifuncmod8.c index c004367..7c06562 100644 --- a/sysdeps/x86_64/ifuncmod8.c +++ b/sysdeps/x86_64/ifuncmod8.c @@ -28,6 +28,7 @@ foo_impl (float x) } void * +inhibit_stack_protector foo_ifunc (void) { __m128i xmm = _mm_set1_epi32 (-1);