public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Nix <nix@esperi.org.uk>
To: libc-alpha@sourceware.org
Cc: carlos@redhat.com
Subject: [PATCH 03/14] Mark all machinery needed in early static-link init as -fno-stack-protector.
Date: Tue, 23 Feb 2016 23:40:00 -0000	[thread overview]
Message-ID: <1456270777-9083-4-git-send-email-nix@esperi.org.uk> (raw)
In-Reply-To: <1456270777-9083-1-git-send-email-nix@esperi.org.uk>

From: Nick Alcock <nick.alcock@oracle.com>

The startup code in csu/, brk() and sbrk(), and the
__pthread_initialize_tcb_internal() function we just introduced are
needed very early in initialization of a statically-linked program,
before the stack guard is initialized. Mark all of these as
-fno-stack-protector.

We also finally introduce @libc_cv_ssp@, substituted by the configury
changes made much earlier, to detect the case when -fno-stack-protector
is supported by the compiler, and unconditionally pass it in when this
is the case, whether or not --enable-stack-protector is passed to
configure.  (This means that it'll even work when the compiler's been
hacked to pass -fstack-protector by default, unless the hackage is so
broken that it does so in a way that is impossible to override.)

(At one point we marked __libc_fatal() as non-stack-protected too,
but this was pointless: all it did was call other routines which *are*
stack-protected.  The earliest __libc_fatal() call is in the
DL_SYSDEP_OSCHECK hook on some platforms: this is fine, since it is
after TLS and stack-canary initialization.  I have tested invocation
of programs statically and dynamically linked against this glibc on
older kernels on x86, and they still "work", i.e. fail with the
appropriate message.)

v2: No longer mark memcpy() as -fno-stack-protector.
---
 config.make.in | 1 +
 csu/Makefile   | 7 +++++++
 misc/Makefile  | 6 ++++++
 nptl/Makefile  | 5 +++++
 4 files changed, 19 insertions(+)

diff --git a/config.make.in b/config.make.in
index 05ed6ec..847931f 100644
--- a/config.make.in
+++ b/config.make.in
@@ -55,6 +55,7 @@ with-fp = @with_fp@
 enable-timezone-tools = @enable_timezone_tools@
 unwind-find-fde = @libc_cv_gcc_unwind_find_fde@
 have-fpie = @libc_cv_fpie@
+have-ssp = @libc_cv_ssp@
 stack-protector = @stack_protector@
 have-selinux = @have_selinux@
 have-libaudit = @have_libaudit@
diff --git a/csu/Makefile b/csu/Makefile
index 31e8bb9..8d7cbb5 100644
--- a/csu/Makefile
+++ b/csu/Makefile
@@ -45,6 +45,13 @@ before-compile += $(objpfx)version-info.h
 tests := tst-empty tst-atomic tst-atomic-long
 tests-static := tst-empty
 
+ifeq ($(have-ssp),yes)
+CFLAGS-.o += -fno-stack-protector
+CFLAGS-.og += -fno-stack-protector
+CFLAGS-.op += -fno-stack-protector
+CFLAGS-.os += -fno-stack-protector
+endif
+
 ifeq (yes,$(build-shared))
 extra-objs += S$(start-installed-name) gmon-start.os
 ifneq ($(start-installed-name),$(static-start-installed-name))
diff --git a/misc/Makefile b/misc/Makefile
index d7bbc85..ba5c5d0 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -99,6 +99,12 @@ CFLAGS-getusershell.c = -fexceptions
 CFLAGS-err.c = -fexceptions
 CFLAGS-tst-tsearch.c = $(stack-align-test-flags)
 
+ifeq ($(have-ssp),yes)
+# Called during static library initialization.
+CFLAGS-sbrk.c = -fno-stack-protector
+CFLAGS-brk.c = -fno-stack-protector
+endif
+
 include ../Rules
 
 $(objpfx)libg.a: $(dep-dummy-lib); $(make-dummy-lib)
diff --git a/nptl/Makefile b/nptl/Makefile
index dc3ccab..a1d52a2 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -327,6 +327,11 @@ tests += tst-execstack
 endif
 endif
 
+ifeq ($(have-ssp),yes)
+# Parts of nptl-init.c are called before the stack guard is initialized.
+CFLAGS-nptl-init.c += -fno-stack-protector
+endif
+
 modules-names = tst-atfork2mod tst-tls3mod tst-tls4moda tst-tls4modb \
 		tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
 		tst-tls5modd tst-tls5mode tst-tls5modf tst-stack4mod \
-- 
2.7.0.198.g6dd47b6

  parent reply	other threads:[~2016-02-23 23:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23 23:39 --enable-stack-protector for glibc, v2, now with sparc Nix
2016-02-23 23:39 ` [PATCH 07/14] Prevent the rtld mapfile computation from dragging in __stack_chk_fail() Nix
2016-02-23 23:39 ` [PATCH 05/14] Allow overriding of CFLAGS as well as CPPFLAGS for rtld Nix
2016-02-23 23:40 ` [PATCH 11/14] Work even with compilers hacked to enable -fstack-protector by default Nix
2016-02-23 23:40 ` [PATCH 04/14] Open-code the memcpy() at static TLS initialization time Nix
2016-02-23 23:40 ` Nix [this message]
2016-02-23 23:40 ` [PATCH 14/14] sparc: do not stack-protect the sigreturn handler Nix
2016-02-23 23:40 ` [PATCH 10/14] Enable -fstack-protector=* when requested by configure Nix
2016-02-24  9:46   ` Andreas Schwab
2016-02-24 17:16     ` Nix
2016-02-23 23:40 ` [PATCH 01/14] Configury support for --enable-stack-protector Nix
2016-02-23 23:40 ` [PATCH 09/14] Link various tests with -fno-stack-protector Nix
2016-02-24 13:07   ` Andreas Schwab
2016-02-24 13:09     ` Nix
2016-02-23 23:40 ` [PATCH 13/14] Avoid stack-protecting certain functions called from assembly Nix
2016-02-23 23:40 ` [PATCH 02/14] Initialize the stack guard earlier when linking statically Nix
2016-02-23 23:40 ` [PATCH 12/14] Drop explicit stack-protection of pieces of the system Nix
2016-02-23 23:40 ` [PATCH 08/14] Link libc.so with libc_nonshared.a to pull in __stack_chk_fail Nix
2016-02-24  0:57 ` [PATCH 06/14] Compile the entire dynamic linker with -fno-stack-protector Nix
2016-02-24 23:28 --enable-stack-protector for glibc, v3 Nix
2016-02-24 23:29 ` [PATCH 03/14] Mark all machinery needed in early static-link init as -fno-stack-protector Nix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456270777-9083-4-git-send-email-nix@esperi.org.uk \
    --to=nix@esperi.org.uk \
    --cc=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).