From patchwork Tue Jun 7 11:06:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nix X-Patchwork-Id: 12845 Received: (qmail 61933 invoked by alias); 7 Jun 2016 11:26:38 -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 61922 invoked by uid 89); 7 Jun 2016 11:26:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=routes, Hx-languages-length:2486 X-HELO: mail.esperi.org.uk From: Nix To: libc-alpha@sourceware.org Cc: fweimer@redhat.com, Nick Alcock Subject: [PATCH 09/14 v6] Add stack_chk_fail_local to libc.so. Date: Tue, 7 Jun 2016 12:06:11 +0100 Message-Id: <1465297576-10981-10-git-send-email-nix@esperi.org.uk> In-Reply-To: <1465297576-10981-1-git-send-email-nix@esperi.org.uk> References: <1465297576-10981-1-git-send-email-nix@esperi.org.uk> X-DCC--Metrics: spindle 1282; Body=4 Fuz1=4 Fuz2=4 From: Nick Alcock This is required by the next commit, which routes all __stack_chk_fail() calls in libc.so via this function to avoid the PLT. It has be duplicated in libc.so and libc_nonshared.a because its entire reason for existence is to be hidden and avoid the PLT, so the copy in libc.so is not visible from elsewhere. 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. * debug/libc-stack_chk_fail_local.c: New file. * debug/Makefile (routines): Add it. (shared-only-routines): Likewise. (CFLAGS-stack_chk_fail.c): Use $(no-stack-protector). (CFLAGS-stack_chk_fail_local.c): Likewise. (CFLAGS-libc-stack_chk_fail_local.c): Likewise. --- debug/Makefile | 14 +++++++++++++- debug/libc-stack_chk_fail_local.c | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 debug/libc-stack_chk_fail_local.c diff --git a/debug/Makefile b/debug/Makefile index 6b5f31e..27da081 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -48,9 +48,21 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \ vdprintf_chk obprintf_chk \ longjmp_chk ____longjmp_chk \ fdelt_chk poll_chk ppoll_chk \ - stack_chk_fail fortify_fail \ + stack_chk_fail fortify_fail libc-stack_chk_fail_local \ $(static-only-routines) + +# stack_chk_fail_local must be non-PIC, thus static-only, but we also +# want an identical thunk hidden in libc.so to avoid going via the PLT. + static-only-routines := warning-nop stack_chk_fail_local +shared-only-routines += libc-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-libc-stack_chk_fail_local.c = $(no-stack-protector) CFLAGS-backtrace.c = -fno-omit-frame-pointer CFLAGS-sprintf_chk.c = $(libio-mtsafe) diff --git a/debug/libc-stack_chk_fail_local.c b/debug/libc-stack_chk_fail_local.c new file mode 100644 index 0000000..73da970 --- /dev/null +++ b/debug/libc-stack_chk_fail_local.c @@ -0,0 +1,3 @@ +/* This goes into the shared libc. */ + +#include