aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2024-05-30 15:43:07 +0200
committerFlorian Weimer <fweimer@redhat.com>2024-05-30 15:48:25 +0200
commit90ee0d87302810f1670a1fbcf9455b883309b1de (patch)
treed7aa1435887404eec44cda4c7d0a061cc930e29f
parentf5bfd0e47c842f47979751297d3b83f34be8476c (diff)
downloadglibc-90ee0d87302810f1670a1fbcf9455b883309b1de.zip
glibc-90ee0d87302810f1670a1fbcf9455b883309b1de.tar.gz
glibc-90ee0d87302810f1670a1fbcf9455b883309b1de.tar.bz2
x86_64: Always initialize ssp_base in the TCB if SHSTK is enabled
-rw-r--r--sysdeps/x86_64/dl-cet.c8
-rw-r--r--sysdeps/x86_64/nptl/nptl_arch_thread_init.h29
2 files changed, 37 insertions, 0 deletions
diff --git a/sysdeps/x86_64/dl-cet.c b/sysdeps/x86_64/dl-cet.c
index 1297c09..d218549 100644
--- a/sysdeps/x86_64/dl-cet.c
+++ b/sysdeps/x86_64/dl-cet.c
@@ -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
index 0000000..64de1d5
--- /dev/null
+++ b/sysdeps/x86_64/nptl/nptl_arch_thread_init.h
@@ -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
+}