]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86_64: Always initialize ssp_base in the TCB if SHSTK is enabled
authorFlorian Weimer <fweimer@redhat.com>
Thu, 30 May 2024 13:43:07 +0000 (15:43 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 30 May 2024 13:48:25 +0000 (15:48 +0200)
sysdeps/x86_64/dl-cet.c
sysdeps/x86_64/nptl/nptl_arch_thread_init.h [new file with mode: 0644]

index 1297c09f841a5fcceab584273e960ec268f7f20a..d21854924de91845aca1ddc97f70d0f44f1321da 100644 (file)
@@ -333,6 +333,14 @@ _dl_cet_setup_features (unsigned int cet_feature)
      enabled from executable, not necessarily supported by kernel.  */
   if (cet_feature != 0)
     {
+      void **ssp;
+      asm ("rdsspq %0"
+          : "=r" (ssp)
+          : "0" (0));
+      if (ssp != NULL)
+       /* The caller is the top-most frame, hence the + 8.  */
+       THREAD_SETMEM (THREAD_SELF, header.ssp_base, ssp + 8);
+
       cet_feature = dl_cet_get_cet_status ();
       if (cet_feature != 0)
        {
diff --git a/sysdeps/x86_64/nptl/nptl_arch_thread_init.h b/sysdeps/x86_64/nptl/nptl_arch_thread_init.h
new file mode 100644 (file)
index 0000000..64de1d5
--- /dev/null
@@ -0,0 +1,29 @@
+/* Architecture-specific thread initialization for NPTL.  x86-64 version.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+static inline __always_inline void
+__nptl_arch_thread_init (void)
+{
+#if CET_ENABLED
+  void **ssp;
+  asm ("rdsspq %0"
+       : "=r" (ssp)
+       : "0" (0));
+  THREAD_SETMEM (THREAD_SELF, header.ssp_base, ssp);
+#endif
+}