]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Unconditionally define __stack_chk_guard [BZ #26817] maskray/stack_chk_guard
authorFangrui Song <maskray@google.com>
Tue, 12 Jan 2021 07:56:32 +0000 (23:56 -0800)
committerFangrui Song <maskray@google.com>
Tue, 12 Jan 2021 07:56:32 +0000 (23:56 -0800)
__stack_chk_guard is currently unavailable on architectures which define
THREAD_SET_STACK_GUARD, so {gcc,clang} -fstack-protector
-mstack-protector-guard=global will fail to link due to the undefined
symbol.

Define __stack_chk_guard to make -mstack-protector-guard=global compiled
user programs work. `#define THREAD_SET_STACK_GUARD` code is moved
outside of `#ifndef __ASSEMBLER__` so that cpp can preprocess
elf/Versions.

22 files changed:
csu/libc-start.c
elf/Versions
elf/rtld.c
sysdeps/i386/nptl/tls.h
sysdeps/ia64/nptl/tls.h
sysdeps/mach/hurd/i386/ld.abilist
sysdeps/mach/hurd/i386/tls.h
sysdeps/powerpc/nptl/tls.h
sysdeps/s390/nptl/tls.h
sysdeps/sparc/nptl/tls.h
sysdeps/unix/sysv/linux/i386/ld.abilist
sysdeps/unix/sysv/linux/ia64/ld.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
sysdeps/x86_64/nptl/tls.h

index db859c3bed1685d594c0776b0cec330db39e79d6..e46d40266485e788eeef27d43849872f215409ca 100644 (file)
@@ -33,11 +33,8 @@ extern void __libc_init_first (int argc, char **argv, char **envp);
 #include <tls.h>
 #ifndef SHARED
 # include <dl-osinfo.h>
-# ifndef THREAD_SET_STACK_GUARD
-/* Only exported for architectures that don't store the stack guard canary
-   in thread local area.  */
+/* Also export to architectures which prefer -mstack-protector-guard=tls.  */
 uintptr_t __stack_chk_guard attribute_relro;
-# endif
 # ifndef  THREAD_SET_POINTER_GUARD
 /* Only exported for architectures that don't store the pointer guard
    value in thread local area.  */
@@ -206,9 +203,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
   uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
 # ifdef THREAD_SET_STACK_GUARD
   THREAD_SET_STACK_GUARD (stack_chk_guard);
-# else
-  __stack_chk_guard = stack_chk_guard;
 # endif
+  __stack_chk_guard = stack_chk_guard;
 
 # ifdef DL_SYSDEP_OSCHECK
   {
index be88c48e6d45a937c1d6a60c499aeff6c83cc5e5..b5a6151aa490bde3bea77cb3bb0a236dc931b9c7 100644 (file)
@@ -1,3 +1,6 @@
+%if __has_include("tls.h")
+%include "tls.h"
+%endif
 libc {
   GLIBC_2.0 {
 %ifdef EXPORT_UNWIND_FIND_FDE
@@ -50,7 +53,15 @@ ld {
   }
   GLIBC_2.4 {
     # stack canary
+%ifndef THREAD_SET_STACK_GUARD
+    __stack_chk_guard;
+%endif
+  }
+  GLIBC_2.33 {
+    # stack canary
+%ifdef THREAD_SET_STACK_GUARD
     __stack_chk_guard;
+%endif
   }
   GLIBC_PRIVATE {
     # Those are in the dynamic linker, but used by libc.so.
index 8d9add90e3e56df901b8525d6810998045e1d5dc..cd70428c4682e073c49e23978f24eab2dc0107fa 100644 (file)
@@ -154,11 +154,8 @@ unsigned int _dl_skip_args attribute_relro attribute_hidden;
 #endif
 rtld_hidden_data_def (_dl_argv)
 
-#ifndef THREAD_SET_STACK_GUARD
-/* Only exported for architectures that don't store the stack guard canary
-   in thread local area.  */
+/* Also export to architectures which prefer -mstack-protector-guard=tls.  */
 uintptr_t __stack_chk_guard attribute_relro;
-#endif
 
 /* Only exported for architectures that don't store the pointer guard
    value in thread local area.  */
@@ -865,9 +862,8 @@ security_init (void)
   uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
 #ifdef THREAD_SET_STACK_GUARD
   THREAD_SET_STACK_GUARD (stack_chk_guard);
-#else
-  __stack_chk_guard = stack_chk_guard;
 #endif
+  __stack_chk_guard = stack_chk_guard;
 
   /* Set up the pointer guard as well, if necessary.  */
   uintptr_t pointer_chk_guard
index 86ee1ef30270f960b0db04446797225cd4849b54..c16c2fe6656e78734f560949e2fb10ba3eb7db00 100644 (file)
@@ -68,6 +68,13 @@ _Static_assert (offsetof (tcbhead_t, __private_ss) == 0x30,
    the SSE memory functions.  */
 #define STACK_ALIGN    16
 
+/* Set the stack guard field in TCB head. Referenced by elf/Versions. */
+#define THREAD_SET_STACK_GUARD(value) \
+  THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+#define THREAD_COPY_STACK_GUARD(descr) \
+  ((descr)->header.stack_guard                                               \
+   = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
 #ifndef __ASSEMBLER__
 /* Get system call information.  */
 # include <sysdep.h>
@@ -358,14 +365,6 @@ tls_fill_user_desc (union user_desc_init *desc,
        }})
 
 
-/* Set the stack guard field in TCB head.  */
-#define THREAD_SET_STACK_GUARD(value) \
-  THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
-#define THREAD_COPY_STACK_GUARD(descr) \
-  ((descr)->header.stack_guard                                               \
-   = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
-
-
 /* Set the pointer guard field in the TCB head.  */
 #define THREAD_SET_POINTER_GUARD(value) \
   THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
index 66d9bf3189f0b727486f47c0c4ed66973240ac4e..11f9a421c0ff0037d764fbd3ec9a9245b8328ed2 100644 (file)
@@ -46,6 +46,13 @@ register struct pthread *__thread_self __asm__("r13");
 /* Alignment requirement for the stack.  */
 #define STACK_ALIGN    16
 
+/* Set the stack guard field in TCB head. Referenced by elf/Versions.  */
+#define THREAD_SET_STACK_GUARD(value) \
+  (((uintptr_t *) __thread_self)[-1] = (value))
+#define THREAD_COPY_STACK_GUARD(descr) \
+  (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
+   = ((uintptr_t *) __thread_self)[-1])
+
 #ifndef __ASSEMBLER__
 /* Get system call information.  */
 # include <sysdep.h>
@@ -138,13 +145,6 @@ register struct pthread *__thread_self __asm__("r13");
 #define THREAD_SETMEM_NC(descr, member, idx, value) \
   descr->member[idx] = (value)
 
-/* Set the stack guard field in TCB head.  */
-#define THREAD_SET_STACK_GUARD(value) \
-  (((uintptr_t *) __thread_self)[-1] = (value))
-#define THREAD_COPY_STACK_GUARD(descr) \
-  (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
-   = ((uintptr_t *) __thread_self)[-1])
-
 /* Set the pointer guard field in TCB head.  */
 #define THREAD_GET_POINTER_GUARD() \
   (((uintptr_t *) __thread_self)[-2])
index 751664bcdaf69a2482b71da692ad8b9fd4ace421..b3f2fdc5d5356e8b75200d9a240341ce518f686d 100644 (file)
@@ -16,4 +16,5 @@ GLIBC_2.2.6 _r_debug D 0x14
 GLIBC_2.2.6 abort F
 GLIBC_2.3 ___tls_get_addr F
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x4
 GLIBC_2.33 __x86_get_cpu_features F
index 057b2613f3e62b0316ae77bed97acf71a8bfbe19..1413ee63b2348d1d6c315e77a2f4e376b117ffde 100644 (file)
@@ -79,6 +79,13 @@ typedef struct
    "Segment Base".)  On such machines, a cache line is 64 bytes.  */
 #define TCB_ALIGNMENT          64
 
+/* Set the stack guard field in TCB head. Referenced by elf/Versions.  */
+#define THREAD_SET_STACK_GUARD(value) \
+  THREAD_SETMEM (THREAD_SELF, stack_guard, value)
+#define THREAD_COPY_STACK_GUARD(descr) \
+  ((descr)->stack_guard                                                              \
+   = THREAD_GETMEM (THREAD_SELF, stack_guard))
+
 #ifndef __ASSEMBLER__
 
 /* Use i386-specific RPCs to arrange that %gs segment register prefix
@@ -296,13 +303,6 @@ out:
      _dtv; })
 
 
-/* Set the stack guard field in TCB head.  */
-#define THREAD_SET_STACK_GUARD(value) \
-  THREAD_SETMEM (THREAD_SELF, stack_guard, value)
-#define THREAD_COPY_STACK_GUARD(descr) \
-  ((descr)->stack_guard                                                              \
-   = THREAD_GETMEM (THREAD_SELF, stack_guard))
-
 /* Set the pointer guard field in the TCB head.  */
 #define THREAD_SET_POINTER_GUARD(value) \
   THREAD_SETMEM (THREAD_SELF, pointer_guard, value)
index 6c779b6609147d54fb0c04e17d5587e358c84e97..db56e04f819e3851bd0bec2272212cd709c9828e 100644 (file)
 # include <asm/ptrace.h>
 #endif /* __ASSEMBLER__ */
 
+/* Set the stack guard field in TCB head. Used by elf/Versions.  */
+# define THREAD_SET_STACK_GUARD(value) \
+    (((tcbhead_t *) ((char *) __thread_register                                      \
+                    - TLS_TCB_OFFSET))[-1].stack_guard = (value))
+# define THREAD_COPY_STACK_GUARD(descr) \
+    (((tcbhead_t *) ((char *) (descr)                                        \
+                    + TLS_PRE_TCB_SIZE))[-1].stack_guard                     \
+     = ((tcbhead_t *) ((char *) __thread_register                            \
+                      - TLS_TCB_OFFSET))[-1].stack_guard)
+
 #ifndef __powerpc64__
 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
 # define PT_THREAD_POINTER PT_R2
@@ -191,16 +201,6 @@ typedef struct
 # define THREAD_SETMEM_NC(descr, member, idx, value) \
     ((void)(descr), (THREAD_SELF)->member[idx] = (value))
 
-/* Set the stack guard field in TCB head.  */
-# define THREAD_SET_STACK_GUARD(value) \
-    (((tcbhead_t *) ((char *) __thread_register                                      \
-                    - TLS_TCB_OFFSET))[-1].stack_guard = (value))
-# define THREAD_COPY_STACK_GUARD(descr) \
-    (((tcbhead_t *) ((char *) (descr)                                        \
-                    + TLS_PRE_TCB_SIZE))[-1].stack_guard                     \
-     = ((tcbhead_t *) ((char *) __thread_register                            \
-                      - TLS_TCB_OFFSET))[-1].stack_guard)
-
 /* Set the stack guard field in TCB head.  */
 # define THREAD_GET_POINTER_GUARD() \
     (((tcbhead_t *) ((char *) __thread_register                                      \
index efb52515e05c06a9afe57f23b42ebd8c4e78174a..f01d835ea4a9112801f1f521677e7547cf271462 100644 (file)
@@ -57,6 +57,18 @@ typedef struct
    the SSE memory functions.  */
 #define STACK_ALIGN    16
 
+/* Set the stack guard field in TCB head. Referenced by elf/Versions.  */
+#define THREAD_SET_STACK_GUARD(value) \
+  do                                                                         \
+   {                                                                         \
+     __asm__ __volatile__ ("" : : : "a0", "a1");                             \
+     THREAD_SETMEM (THREAD_SELF, header.stack_guard, value);                 \
+   }                                                                         \
+  while (0)
+#define THREAD_COPY_STACK_GUARD(descr) \
+  ((descr)->header.stack_guard                                               \
+   = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
 #ifndef __ASSEMBLER__
 /* Get system call information.  */
 # include <sysdep.h>
@@ -145,18 +157,6 @@ typedef struct
 #define THREAD_SETMEM_NC(descr, member, idx, value) \
   descr->member[idx] = (value)
 
-/* Set the stack guard field in TCB head.  */
-#define THREAD_SET_STACK_GUARD(value) \
-  do                                                                         \
-   {                                                                         \
-     __asm__ __volatile__ ("" : : : "a0", "a1");                             \
-     THREAD_SETMEM (THREAD_SELF, header.stack_guard, value);                 \
-   }                                                                         \
-  while (0)
-#define THREAD_COPY_STACK_GUARD(descr) \
-  ((descr)->header.stack_guard                                               \
-   = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
-
 /* s390 doesn't have HP_TIMING_*, so for the time being
    use stack_guard as pointer_guard.  */
 #define THREAD_GET_POINTER_GUARD() \
index dd1eb82a595619a98c30c330a7a616ec958801ea..764fae5dd4a18e19e545dee8bb292a4ac39e29f0 100644 (file)
@@ -51,6 +51,12 @@ typedef struct
 # include <tcb-offsets.h>
 #endif /* __ASSEMBLER__ */
 
+/* Set the stack guard field in TCB head. Referenced by elf/Versions.  */
+#define THREAD_SET_STACK_GUARD(value) \
+  THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+# define THREAD_COPY_STACK_GUARD(descr) \
+  ((descr)->header.stack_guard \
+   = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
 
 #ifndef __ASSEMBLER__
 /* Get system call information.  */
@@ -122,13 +128,6 @@ register struct pthread *__thread_self __asm__("%g7");
 #define THREAD_SETMEM_NC(descr, member, idx, value) \
   descr->member[idx] = (value)
 
-/* Set the stack guard field in TCB head.  */
-#define THREAD_SET_STACK_GUARD(value) \
-  THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
-# define THREAD_COPY_STACK_GUARD(descr) \
-  ((descr)->header.stack_guard \
-   = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
-
 /* Get/set the stack guard field in TCB head.  */
 #define THREAD_GET_POINTER_GUARD() \
   THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
index 04655651b0ad26c0397b3033fe3a8d6d6ccbf7fd..58968d772e78f543d25ffe910ae53457631118e4 100644 (file)
@@ -3,4 +3,5 @@ GLIBC_2.1 __libc_stack_end D 0x4
 GLIBC_2.1 _dl_mcount F
 GLIBC_2.3 ___tls_get_addr F
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x4
 GLIBC_2.33 __x86_get_cpu_features F
index 33f91199bfa516fbad2b738d27eef634e7ed6d56..782a31dda4cf49c2c05d30845ebb93cf40075f8b 100644 (file)
@@ -2,3 +2,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
 GLIBC_2.2 _dl_mcount F
 GLIBC_2.2 _r_debug D 0x28
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x8
index 4bbfba7a61c7a5ef05eeb10c331072768d101b17..5f0f61ffe8eaa2c905a7d9c0cfab1bf50c87b034 100644 (file)
@@ -4,3 +4,4 @@ GLIBC_2.1 _dl_mcount F
 GLIBC_2.22 __tls_get_addr_opt F
 GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x4
index 283fb4510bea40ba233662c44b9c7d99514586cf..2789aacf9840294bfa369e5874e645c538ff7c38 100644 (file)
@@ -4,3 +4,4 @@ GLIBC_2.3 __libc_stack_end D 0x8
 GLIBC_2.3 __tls_get_addr F
 GLIBC_2.3 _dl_mcount F
 GLIBC_2.3 _r_debug D 0x28
+GLIBC_2.33 __stack_chk_guard D 0x8
index b1f313c7cd33defc02660a9ab1a934b0c19fbf62..819d9b8f77a422358c122abcf584fc508e21389a 100644 (file)
@@ -4,3 +4,4 @@ GLIBC_2.17 _dl_mcount F
 GLIBC_2.17 _r_debug D 0x28
 GLIBC_2.22 __tls_get_addr_opt F
 GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
+GLIBC_2.33 __stack_chk_guard D 0x8
index b56f005bebd3baf158797bd40843fba3193e8c43..f0d850a2081b2a58e735e55714e95258ff67a5ed 100644 (file)
@@ -2,3 +2,4 @@ GLIBC_2.0 _r_debug D 0x14
 GLIBC_2.1 __libc_stack_end D 0x4
 GLIBC_2.1 _dl_mcount F
 GLIBC_2.3 __tls_get_offset F
+GLIBC_2.33 __stack_chk_guard D 0x4
index 6f788a086d68aaa500197acbdbc3f08e0e03561b..29a2bafdf8b31898861ace71087d42f5793f3843 100644 (file)
@@ -2,3 +2,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
 GLIBC_2.2 _dl_mcount F
 GLIBC_2.2 _r_debug D 0x28
 GLIBC_2.3 __tls_get_offset F
+GLIBC_2.33 __stack_chk_guard D 0x8
index 0c6610e3c2f00cf3d5a8af0a6890487e477e6427..345118a14863de3277b9ce001f60f08b70c2218f 100644 (file)
@@ -2,3 +2,4 @@ GLIBC_2.0 _r_debug D 0x14
 GLIBC_2.1 __libc_stack_end D 0x4
 GLIBC_2.1 _dl_mcount F
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x4
index 33f91199bfa516fbad2b738d27eef634e7ed6d56..782a31dda4cf49c2c05d30845ebb93cf40075f8b 100644 (file)
@@ -2,3 +2,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
 GLIBC_2.2 _dl_mcount F
 GLIBC_2.2 _r_debug D 0x28
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x8
index e632c6198eabd6362b65165d49c69b44b593e984..6741524283efd5ff289d73964760a0285ed691fa 100644 (file)
@@ -2,4 +2,5 @@ GLIBC_2.2.5 __libc_stack_end D 0x8
 GLIBC_2.2.5 _dl_mcount F
 GLIBC_2.2.5 _r_debug D 0x28
 GLIBC_2.3 __tls_get_addr F
+GLIBC_2.33 __stack_chk_guard D 0x8
 GLIBC_2.33 __x86_get_cpu_features F
index 9d9d0befde2390ad1d8968725a3602fd01956121..a995a3081850bd2c8680bb2b5dcc74deb3fc4d96 100644 (file)
@@ -2,4 +2,5 @@ GLIBC_2.16 __libc_stack_end D 0x4
 GLIBC_2.16 __tls_get_addr F
 GLIBC_2.16 _dl_mcount F
 GLIBC_2.16 _r_debug D 0x14
+GLIBC_2.33 __stack_chk_guard D 0x4
 GLIBC_2.33 __x86_get_cpu_features F
index 20f0958780b78f4f6f05c24101b77680680b22ec..064927b2108cd9ec7090d3dec3e75fb9058e3cab 100644 (file)
@@ -94,6 +94,13 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80,
 /* Alignment requirement for the stack.  */
 #define STACK_ALIGN    16
 
+/* Set the stack guard field in TCB head. Used by elf/Versions.  */
+# define THREAD_SET_STACK_GUARD(value) \
+    THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+# define THREAD_COPY_STACK_GUARD(descr) \
+    ((descr)->header.stack_guard                                             \
+     = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
 
 #ifndef __ASSEMBLER__
 /* Get system call information.  */
@@ -303,14 +310,6 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80,
        }})
 
 
-/* Set the stack guard field in TCB head.  */
-# define THREAD_SET_STACK_GUARD(value) \
-    THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
-# define THREAD_COPY_STACK_GUARD(descr) \
-    ((descr)->header.stack_guard                                             \
-     = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
-
-
 /* Set the pointer guard field in the TCB head.  */
 # define THREAD_SET_POINTER_GUARD(value) \
   THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)