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 dynamic-link/21598] i386 _dl_runtime_resolve/_dl_runtime_profile is incompatible with shadow stack


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

--- Comment #17 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, hjl/cet/property has been created
        at  e04eefe5ee59389a8017e5509c0b1a0d26ced21f (commit)

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

commit e04eefe5ee59389a8017e5509c0b1a0d26ced21f
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jun 28 15:16:46 2017 -0700

    i386: Add _dl_runtime_resolve_shstk/_dl_runtime_profile_shstk [BZ #21598]

    Add SHSTK compatible symbol resolvers to support Shadow Stack in Intel
    Control-flow Enforcement Technology (CET) instructions:

   
https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

    Replace _dl_runtime_resolve and _dl_runtime_profile with
    _dl_runtime_resolve_shstk and _dl_runtime_profile_shstk, respectively if
    SHSTK is enabled.

         [BZ #21598]
         * sysdeps/i386/dl-trampoline.S (_dl_runtime_resolve_shstk): New.
         (_dl_runtime_profile_shstk): Likewise.
         * sysdeps/unix/sysv/linux/i386/dl-cet.c: New file.

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

commit ec13d7eee49929a7e4e867fcfc30c23930fba5cf
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jun 22 04:15:39 2017 -0700

    x86: Support IBT and SHSTK from Intel CET

    Intel Control-flow Enforcement Technology (CET) instructions:

   
https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-en
    forcement-technology-preview.pdf

    includes Indirect Branch Tracking (IBT) and Shadow Stack (SHSTK).

    GNU_PROPERTY_X86_FEATURE_1_IBT is added to GNU program property to
    indicate that all executable sections are compatible with IBT when
    ENDBR instruction starts each valid target where an indirect branch
    instruction can land.  GNU_PROPERTY_X86_FEATURE_1_IBT is set on output
    only if it is set on all relocatable inputs.

    On an IBT capable processor, the following steps should be taken:

    1. When loading an executable, if GNU_PROPERTY_X86_FEATURE_1_IBT is
    set on the executable, enable IBT.
    2. If IBT is enabled, when loading a shared object without
    GNU_PROPERTY_X86_FEATURE_1_IBT:
      a. If legacy interwork is allowed, then mark all pages in executable
         PT_LOAD segments in legacy code page bitmap.  Failure of legacy code
         page bitmap allocation causes an error.
      b. If legacy interwork isn't allowed, it causes an error.

    GNU_PROPERTY_X86_FEATURE_1_SHSTK is added to GNU program property to
    indicate that all executable sections are compatible with SHSTK where
    return address popped from shadow stack always matches return address
    popped from normal stack.  GNU_PROPERTY_X86_FEATURE_1_SHSTK is set on
    output only if it is set on all relocatable inputs.

    On a SHSTK capable processor, the following steps should be taken:

    1. When loading an executable, if GNU_PROPERTY_X86_FEATURE_1_SHSTK is
    set on the executable as well as all shared objects loaded via the
    DT_NEEDED tag, enable SHSTK.
    2. After SHSTK is enabled, it is an error to load a shared object
    without GNU_PROPERTY_X86_FEATURE_1_SHSTK.

    When glibc is built with a compiler which defines defines__IBT__ and
    __SHSTK__, CET is enabled, unless --disable-cet is used to configure
    glibc.  When CET is enabled, both compiler and assembler must support
    CET.  Otherwise, it is a configure-time error.

    To support CET run-time control,

    1. _dl_x86_feature_1 is added to the writable ld.so namespace to indicate
    if IBT or SHSTK are enabled at run-time.
    2. For dynamic executables:
       a. A l_cet field is added to struct link_map to indicate if IBT or
          SHSTK is enabled in an ELF module.  The optional DL_PROCESS_PT_NOTE
          is called to process PT_NOTE segment for GNU program property and
          set l_cet.
       b. _dl_start_user calls _dl_cet_init, instead of _dl_init, which sets
         _dl_x86_feature_1 as well as sets up IBT and SHSTK.
    3. For static executables, _dl_setup_cet is called to process PT_NOTE
    segment for GNU program property to set _dl_x86_feature_1 as well as set
    up IBT and SHSTK.

    <sys/cet.h> is added so that it can be included by assembly codes to
    add GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK
    to GNU program property if __IBT__ or __SHSTK__ is defined.

        * config.h.in (ENABLE_CET): New #undef.
        * configure.ac: Add --enable-cet.
        * configure: Regenerated.
        * elf/dl-load.c (filebuf): Moved before "dynamic-link.h".
        (_dl_map_object_from_fd): Call DL_PROCESS_PT_NOTE on PT_NOTE
        segment if DL_PROCESS_PT_NOTE is defined.
        * elf/rtld.c (dl_main): Likewise.
        * elf/dl-support.c: Include <dl-procruntime.c>.
        * include/link.h: Include <link_map.h>.
        * sysdeps/generic/dl-procruntime.c: New file.
        * sysdeps/generic/link_map.h: Likewise.
        * sysdeps/unix/sysv/linux/i386/dl-machine.h: Likewise.
        * sysdeps/unix/sysv/linux/x86/configure: Likewise.
        * sysdeps/unix/sysv/linux/x86/configure.ac: Likewise.
        * sysdeps/unix/sysv/linux/x86/dl-cet-nonshared.c: Likewise.
        * sysdeps/unix/sysv/linux/x86/dl-cet.c: Likewise.
        * sysdeps/unix/sysv/linux/x86/dl-cet.h: Likewise.
        * sysdeps/unix/sysv/linux/x86/dl-procruntime.c: Likewise.
        * sysdeps/unix/sysv/linux/x86/libc-start.c: Likewise.
        * sysdeps/unix/sysv/linux/x86/link_map.h: Likewise.
        * sysdeps/unix/sysv/linux/x86/sys/cet.h: Likewise.
        * sysdeps/unix/sysv/linux/x86_64/dl-machine.h: Likewise.
        * sysdeps/generic/ldsodefs.h: Include <dl-procruntime.c> in
        the writable ld.so namespace.
        * sysdeps/i386/dl-machine.h (DL_INIT): New.
        (_dl_start_user): Replace _dl_init with DL_INIT.
        * sysdeps/unix/sysv/linux/x86/Makefile (sysdep_routines): Add
        dl-cet-nonshared if CET is enabled.
        (sysdep-dl-routines): Add dl-cet if CET is enabled.
        (sysdep_headers): Add sys/cet.h if CET is enabled.
        (asm-CPPFLAGS): Include sysdeps/unix/sysv/linux/x86/sys/cet.h
        if CET is enabled.
        * sysdeps/x86/libc-start.c (ARCH_INIT_CPU_FEATURES): Define
        only if it is undefined.
        * sysdeps/x86_64/dl-machine.h (DL_INIT): New.
        (_dl_start_user): Replace _dl_init with DL_INIT.

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

commit 31e1594811caf5d87d236cd9f58e84fee92e6714
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jun 22 08:51:42 2017 -0700

    x86: Add IBT/SHSTK bits to cpu-features

    Add IBT/SHSTK bits to cpu-features for Shadow Stack in Intel Control-flow
    Enforcement Technology (CET) instructions:

   
https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

        * sysdeps/x86/cpu-features.h (bit_cpu_BIT): New.
        (bit_cpu_SHSTK): Likewise.
        (index_cpu_IBT): Likewise.
        (index_cpu_SHSTK): Likewise.
        (reg_IBT): Likewise.
        (reg_SHSTK): Likewise.

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

commit 40215e85a8f00b85c1e2b96cb4b37c23fc3831cd
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jun 21 13:07:05 2017 -0700

    Add NT_GNU_PROPERTY_TYPE_0 macros

    Add macros used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0).

        * elf/elf.h (NT_GNU_PROPERTY_TYPE_0): New.
        (NOTE_GNU_PROPERTY_SECTION_NAME): Likewise.
        (GNU_PROPERTY_STACK_SIZE): Likewie.
        (GNU_PROPERTY_NO_COPY_ON_PROTECTED): Likewie.
        (GNU_PROPERTY_LOPROC): Likewise.
        (GNU_PROPERTY_HIPROC): Likewise.
        (GNU_PROPERTY_LOUSER): Likewise.
        (GNU_PROPERTY_HIUSER): Likewise.
        (GNU_PROPERTY_X86_ISA_1_USED): Likwise.
        (GNU_PROPERTY_X86_ISA_1_NEEDED): Likwise.
        (GNU_PROPERTY_X86_FEATURE_1_AND): Likwise.
        (GNU_PROPERTY_X86_ISA_1_486): Likwise.
        (GNU_PROPERTY_X86_ISA_1_586): Likwise.
        (GNU_PROPERTY_X86_ISA_1_686): Likwise.
        (GNU_PROPERTY_X86_ISA_1_SSE): Likwise.
        (GNU_PROPERTY_X86_ISA_1_SSE2): Likwise.
        (GNU_PROPERTY_X86_ISA_1_SSE3): Likwise.
        (GNU_PROPERTY_X86_ISA_1_SSSE3): Likwise.
        (GNU_PROPERTY_X86_ISA_1_SSE4_1): Likwise.
        (GNU_PROPERTY_X86_ISA_1_SSE4_2): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX2): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512F): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512CD): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512ER): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512PF): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512VL): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512DQ): Likwise.
        (GNU_PROPERTY_X86_ISA_1_AVX512BW): Likwise.
        (GNU_PROPERTY_X86_FEATURE_1_IBT): Likwise.
        (GNU_PROPERTY_X86_FEATURE_1_SHSTK): Likwise.

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

commit fd362b682226c8597c1b01a648d1d49423bb8ac3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Jun 16 14:27:02 2017 -0700

    Add private_function for private functions within glibc

    i386 _dl_runtime_resolve:

            movl (%esp), %ecx
            movl %eax, (%esp)       # Store the function address.
            movl 4(%esp), %eax
            ret $12                 # Jump to function address.

    is incompatible with Shadow Stack in Intel Control-flow Enforcement
    Technology (CET) instructions:

   
https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf

    since shadow stack doesn't match return stack.  We need to use register
    indirect branch via %ecx.  That means only 2 parameters can be passed
    in registers for external function calls with lazy binding.  However,
    internal_function, which should be used only with hidden function, is
    defined as

     # define internal_function __attribute__ ((regparm (3), stdcall))

    and used with private function calls between different shared objects of
    glibc.  We introduce private_function for such purpose:

     # define private_function __attribute__ ((regparm (2), stdcall))

    so that %ecx can be used by _dl_runtime_resolve as scratch register.

        [BZ #21598]
        * config.h.in (USE_REGPARMS): Removed.
        (internal_function): Undef.
        (private_function): New.  Undef.
        * debug/fortify_fail.c (__fortify_fail): Replace internal_function
        with private_function.
        * elf/dl-addr.c (_dl_addr): Likewise.
        * elf/dl-error-skeleton.c (_dl_signal_error): Likewise.
        (_dl_catch_error): Likewise.
        * elf/dl-execstack.c (_dl_make_stack_executable): Likewise.
        * elf/dl-load.c (_dl_rtld_di_serinfo): Likewise.
        * elf/dl-open.c (_dl_find_dso_for_object): Likewise.
        * elf/dl-support.c (_dl_make_stack_executable_hook): Likewise.
        * elf/dl-sym.c (_dl_vsym): Likewise.
        (_dl_sym): Likewise.
        * elf/dl-tls.c (_dl_get_tls_static_info): Likewise.
        (_dl_allocate_tls_init): Likewise.
        (_dl_allocate_tls): Likewise.
        (_dl_deallocate_tls): Likewise.
        * grp/grp-merge.c (__copy_grp): Likewise.
        (__merge_grp): Likewise.
        * grp/grp-merge.h (__copy_grp): Likewise.
        (__merge_grp): Likewise.
        * include/dlfcn.h (_dl_addr): Likewise.
        (_dl_sym): Likewise.
        (_dl_vsym): Likewise.
        * include/rpc/pmap_clnt.h (__libc_rpc_getport): Likewise.
        * include/stdio.h (__fortify_fail): Likewise.
        * include/stdlib.h (__strtof_nan): Likewise.
        (__strtod_nan): Likewise.
        (__strtold_nan): Likewise.
        (__wcstof_nan): Likewise.
        (__wcstod_nan): Likewise.
        (__wcstold_nan): Likewise.
        (__strtof128_nan): Likewise.
        (__wcstof128_nan): Likewise.
        * inet/inet6_scopeid_pton.c (__inet6_scopeid_pton): Likewise.
        * inet/net-internal.h (__inet6_scopeid_pton): Likewise.
        * nptl/allocatestack.c (__make_stacks_executable): Likewise.
        * nptl/libc_pthread_init.c (__libc_pthread_init): Likewise.
        * nptl/pthreadP.h (__make_stacks_executable): Likewise.
        (__libc_pthread_init): Likewise.
        * nss/XXX-lookup.c (DB_LOOKUP_FCT): Likewise.
        (DB_COMPAT_FCT): Likewise.
        * nss/getXXbyYY_r.c (DB_LOOKUP_FCT): Likewise.
        * nss/getXXent_r.c (DB_LOOKUP_FCT): Likewise.
        * nss/nsswitch.h (db_lookup_function): Likewise.
        * resolv/gai_misc.h (__gai_sigqueue): Likewise.
        * resolv/gai_sigqueue.c (__gai_sigqueue): Likewise.
        * stdlib/strtod_nan_main.c (STRTOD_NAN): Likewise.
        * sunrpc/pm_getport.c (__libc_rpc_getport): Likewise.
        * sysdeps/generic/ldsodefs.h (_dl_make_stack_executable_hook):
        Likewise.
        (_dl_make_stack_executable): Likewise.
        (_dl_signal_error): Likewise.
        (_dl_catch_error): Likewise.
        (_dl_rtld_di_serinfo): Likewise.
        (_dl_allocate_tls): Likewise.
        (_dl_get_tls_static_info): Likewise.
        (_dl_allocate_tls_init): Likewise.
        (_dl_deallocate_tls): Likewise.
        (_dl_find_dso_for_object): Likewise.
        * sysdeps/unix/sysv/linux/dl-execstack.c
        (_dl_make_stack_executable): Likewise.
        * sysdeps/unix/sysv/linux/gai_sigqueue.c (__gai_sigqueue):
        Likewise.
        * sysdeps/unix/sysv/linux/netlink_assert_response.c
        (__netlink_assert_response): Likewise.
        * sysdeps/unix/sysv/linux/netlinkaccess.h
        (__netlink_assert_response): Likewise.
        * include/libc-symbols.h (private_function): New.
        * sysdeps/i386/configure.ac (USE_REGPARMS): Removed.
        (internal_function): New AC_DEFINE.
        (private_function): Likewise.
        * sysdeps/i386/configure: Regenerated.

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

-- 
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]