This is the mail archive of the glibc-bugs@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]

[Bug build/7065] Support building glibc with -fstack-protector or -fstack-protector-all


https://sourceware.org/bugzilla/show_bug.cgi?id=7065

--- Comment #20 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, fw/stack-protector has been created
        at  82f2eb623ce1d9bd0a4d2c45d9d47688e71ed383 (commit)

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=82f2eb623ce1d9bd0a4d2c45d9d47688e71ed383

commit 82f2eb623ce1d9bd0a4d2c45d9d47688e71ed383
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:16 2016 +0100

    Enable -fstack-protector=* when requested by configure.

    This finally turns on all the machinery added in previous commits.

    v3: Wrap long lines.
    v5: Shuffle to the end.

        * Makeconfig (+stack-protector): New variable.
        (+cflags): Use it.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=11533a025509becc37503eab765e8e769e882283

commit 11533a025509becc37503eab765e8e769e882283
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:15 2016 +0100

    Do not stack-protect sigreturn stubs.

    These are called from the kernel with the stack at a carefully-
    chosen location so that the stack frame can be restored: they must not
    move the stack pointer lest garbage be restored into the registers.

    We explicitly inhibit protection for SPARC and for signal/sigreturn.c:
    other arches either define their sigreturn stubs in .S files, or (i386,
    x86_64, mips) use macros expanding to top-level asm blocks and explicit
    labels in the text section to mock up a "function" without telling the
    compiler that one is there at all.

    v2: New.
    v3: Use $(no-stack-protector).
    v4: Use inhibit_stack_protector.
    v7: Add sigreturn.c.

        * signal/Makefile (CFLAGS-sigreturn.c): Use
        $(no-stack-protector).
        * sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c:
        (__rt_sigreturn_stub): Use inhibit_stack_protector.
        * sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
        (__rt_sigreturn_stub): Likewise.
        (__sigreturn_stub): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=14b3c413f1b1dd1bfc0bae45fc042a4de56b85af

commit 14b3c413f1b1dd1bfc0bae45fc042a4de56b85af
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:14 2016 +0100

    Drop explicit stack-protection of pieces of the system.

    This is probably a bad idea: maybe we want to stack-protect some parts
    of the system even when ! --enable-stack-protector.  I can easily adjust
    the patch to do that (though it'll mean introducing a new variable
    analogous to $(stack-protector) but not controlled by the configure
    flag.)

    But if we wanted to value consistency over security, and use the same
    stack-protection configure flag to control everything, this is how we'd
    do it!

    ("Always include at least one patch with something obviously wrong with
    it.")

        * login/Makefile (pt_chown-cflags): Remove.
        * nscd/Makefile (CFLAGS-nscd): Likewise.
        * resolv/Makefile (CFLAGS-libresolv): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=72bb1d426913236e2059e0001afcd75782ef8ff6

commit 72bb1d426913236e2059e0001afcd75782ef8ff6
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:13 2016 +0100

    Link various tests with -fno-stack-protector.

    These tests do not link with libc, so cannot see __stack_chk_fail().

    v3: Use $(no-stack-protector).

        * elf/Makefile (CFLAGS-filtmod1.c): Use $(no-stack-protector) for
        non-libc-linking testcase.
        (CFLAGS-filtmod2.c): Likewise.
        * stdlib/Makefile (CFLAGS-tst-putenvmod.c): Likewise.
        * sysdeps/x86_64/Makefile (CFLAGS-tst-quad1pie.c): Likewise.
        (CFLAGS-tst-quad2pie.c): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f738b8f9e2c63772979e26e491ecf055bff28c50

commit f738b8f9e2c63772979e26e491ecf055bff28c50
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 7 12:06:12 2016 +0100

    De-PLTize __stack_chk_fail internal calls within libc.so.

    We use the same assembler-macro trick we use to de-PLTize
    compiler-generated libcalls to memcpy and memset to redirect
    __stack_chk_fail to __stack_chk_fail_local.

    v5: New.
    v6: Only do it within the shared library: with __stack_chk_fail_local
        in libc_pic.a now we don't need to worry about calls from inside
        other routines in libc_nonshared.a any more.

        * sysdeps/generic/symbol-hacks.h (__stack_chk_fail): Add internal
        alias.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4f2b01de3ab88daefdc239a3c25640153b88283d

commit 4f2b01de3ab88daefdc239a3c25640153b88283d
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:11 2016 +0100

    Add stack_chk_fail_local to libc.so.

    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.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=085d48cdc5494e642cc7016649a75ab200a03781

commit 085d48cdc5494e642cc7016649a75ab200a03781
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:10 2016 +0100

    Work even with compilers hacked to enable -fstack-protector by default.

    With all the machinery we just added, we can easily arrange to work even
    when the compiler passes in -fstack-protector automatically: all the
    necessary bits of glibc are always compiled with -fno-stack-protector
    now.

    So tear out the check in configure, and add appropriate calls to
    -fno-stack-protector in tests that need them (largely those that use
    -nostdlib), since we don't yet have a __stack_chk_fail() that those
    tests can rely upon.  (GCC often provides one, but we cannot rely on
    this, especially not when bootstrapping.)

    v2: No longer pass in -lssp to anything.
    v5: Remove accidentally duplicated $(no_ssp)s.
    v6: Small revisions following Mike Frysinger's review.

        * configure.ac: Add check for unsupported stack-protection level.
        (libc_cv_predef_stack_protector): Remove.
        (no_ssp): New variable.
        (libc_cv_ld_gnu_indirect_function): Use it.
        (libc_cv_asm_set_directive): Likewise.
        (libc_cv_protected_data): Likewise.
        (libc_cv_z_combreloc): Likewise.
        (libc_cv_hashstyle): Likewise.
        (libc_cv_has_glob_dat): Likewise.
        (libc_cv_output_format): Likewise.
        (libc_cv_ehdr_start): Likewise.
        * aclocal.m4 (LIBC_TRY_LINK_STATIC): Likewise.
        (LIBC_LINKER_FEATURE): Likewise.
        (LIBC_COMPILER_BUILTIN_INLINED): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=10bb23d6cd48055ba4974119bc1cf87f4d8063e5

commit 10bb23d6cd48055ba4974119bc1cf87f4d8063e5
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:09 2016 +0100

    Prevent the rtld mapfile computation from dragging in __stack_chk_fail*.

    The previous commit prevented rtld itself from being built with
    -fstack-protector, but this is not quite enough.  We identify which
    objects belong in rtld via a test link and analysis of the resulting
    mapfile.  That link is necessarily done against objects that are
    stack-protected, so drags in __stack_chk_fail_local, __stack_chk_fail,
    and all the libc and libio code they use.

    To stop this happening, use --defsym in the test librtld.map-production
    link to force the linker to predefine these two symbols (to 0, but it
    could be to anything).  (In a real link, this would of course be
    catastrophic, but these object files are never used for anything else.)

    v2: New.
    v6: Dummy out stack_chk_fail_local too.

        * elf/Makefile (dummy-stack-chk-fail): New.
        ($(objpfx)librtld.map): Use it.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0718bc3e5680502076efaba7fe3000d8d896c52f

commit 0718bc3e5680502076efaba7fe3000d8d896c52f
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:08 2016 +0100

    Compile the entire dynamic linker with -fno-stack-protector.

    Also compile corresponding routines in the static libc.a with the same
    flag.

    v3: Use $(no-stack-protector).
        Introduce $(elide-stack-protector) and use it to reduce redundancy.
        Bring all the elisions together textually.

        * elf/Makefile (elide-stack-protector): New.
        (CFLAGS-.os): Use it, eliding $(all-rtld-routines).
        (CFLAGS-.oX): Likewise, eliding $(elide-routines.os).
        (rtld-CFLAGS): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dcb6b662b71117834db8732bd46649557f554a58

commit dcb6b662b71117834db8732bd46649557f554a58
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:06 2016 +0100

    Mark all machinery needed in early static-link init as
-fno-stack-protector.

    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@ and @no_stack_protector@, both
    substituted by the configury changes made 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, when statically linking:
    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 ARM, and they
    still "work", i.e. fail with the appropriate message.)

    v2: No longer mark memcpy() as -fno-stack-protector.
    v3: Use $(no-stack-protector).
    v4: Use inhibit_stack_protector rather than de-protecting all of
nptl-init.c.
    v5: Don't stack-protect brk() and sbrk() in the shared library.
    v7: Add comment in misc/Makefile.  Commit message tweak.

        * config.make.in (have-ssp): New.
        (no-stack-protector): New.
        * csu/Makefile (CFLAGS-.o): Use it.
        (CFLAGS-.og): Likewise.
        (CFLAGS-.op): Likewise.
        (CFLAGS-.os): Likewise.
        * misc/Makefile (CFLAGS-sbrk.o): Likewise.
        (CFLAGS-sbrk.op): Likewise.
        (CFLAGS-sbrk.og): Likewise.
        (CFLAGS-brk.o): Likewise.
        (CFLAGS-brk.op): Likewise.
        (CFLAGS-brk.og): Likewise.
        * nptl/nptl-init.c [!SHARED] (__pthread_initialize_tcb_internal):
        Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d23b1cd0cf47428831e451eb7fda5434982b0675

commit d23b1cd0cf47428831e451eb7fda5434982b0675
Author: Florian Weimer <fweimer@redhat.com>
Date:   Mon Jul 4 12:25:57 2016 +0200

    Define inhibit_stack_protector

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1a410af4d0c0b57ca0eff9546cf18539ebfce8af

commit 1a410af4d0c0b57ca0eff9546cf18539ebfce8af
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:04 2016 +0100

    Initialize the stack guard earlier when linking statically.

    The address of the stack canary is stored in a per-thread variable,
    which means that we must ensure that the TLS area is intialized before
    calling any -fstack-protector'ed functions.  For dynamically linked
    applications, we ensure this (in a later patch) by disabling
    -fstack-protector for the whole dynamic linker, but for static
    applications the AT_ENTRY address is called directly by the kernel, so
    we must deal with the problem differently.

    So split out the part of pthread initialization that sets up the TCB
    (and, more generally, the TLS area) into a separate function (twice --
    there is one implementation in libpthread.a, and another outside it for
    programs that do not link with libpthread), then call it at
    initialization time.  Call that, and move the stack guard initialization
    above the DL_SYSDEP_OSCHECK hook, which if set will probably call
    functions which are stack-protected (it does on Linux and NaCL too).
    We also move apply_irel() up, so that we can still safely call functions
    that require ifuncs while in __pthread_initialize_tcb_internal()
    (though if stack-protection is enabled we still have to avoid calling
    functions that are not stack-protected at this stage).

    v2: describe why we don't move apply_irel() up, and the consequences.
    v6: We can safely move apply_irel() up now.

        * nptl/nptl-init.c (__pthread_initialize_tcb_internal): New
        function, split out from...
        (__pthread_initialize_minimal_internal): ... here.
        * csu/libc-start.c (LIBC_START_MAIN): Call it.  Move stack canary
        and apply_irel() initialization up.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c090aec57a599df633c4ee175dab96c3642f7c84

commit c090aec57a599df633c4ee175dab96c3642f7c84
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Tue Jun 7 12:06:03 2016 +0100

    Configury support for --enable-stack-protector.

    This adds =all and =strong, with obvious semantics, and with a rather
    arbitrarily-chosen default off, which we might well want to change to
    something stronger once this patch has been tested by people other than
    me.

    We don't validate the value of the option yet: that's in a later patch.
    Nor do we use it for anything at this stage.

    We differentiate between 'the compiler understands -fstack-protector'
    and 'the user wanted -fstack-protector' so that we can pass
    -fno-stack-protector in appropriate places even if the user didn't want
    to turn on -fstack-protector for other parts.  (This helps us overcome
    another existing limitation, that glibc doesn't work with GCCs hacked
    to pass in -fstack-protector by default.)

    We might want to add another configuration option to turn on
    -fstack-protector for nscd and other network-facing operations by
    default, but for now I've stuck with one option to control everything.

    v2: documentation in install.texi; better description of the option.
        INSTALL regenerated.
    v3: Substitute in no_stack_protector.
    v6: Small quoting/spacing revisions following Mike Frysinger's review.
        Add STACK_PROTECTOR_LEVEL.
    v7: Quoting changes. Report --enable-stack-protector argument values
        on error.

        [BZ #7065]
        * configure.ac (libc_cv_ssp): Move up.
        (libc_cv_ssp_strong): Likewise.
        (libc_cv_ssp_all): New.
        (stack_protector): Augment, adding -fstack-protector-all.
        (no_stack_protector): New.
        (STACK_PROTECTOR_LEVEL): New.
        (AC_ARG_ENABLE(stack-protector)): New configure flag.
        * manual/install.texi (--enable-stack-protector): Document it.
        * config.h.in (STACK_PROTECTOR_LEVEL): New macro.
        * INSTALL: Regenerate.

-----------------------------------------------------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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