public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/fw/x86-shstk-backtrace] x86_64: Always initialize ssp_base in the TCB if SHSTK is enabled
@ 2024-05-31 20:49 Florian Weimer
  0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2024-05-31 20:49 UTC (permalink / raw)
  To: glibc-cvs

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

commit 90ee0d87302810f1670a1fbcf9455b883309b1de
Author: Florian Weimer <fweimer@redhat.com>
Date:   Thu May 30 15:43:07 2024 +0200

    x86_64: Always initialize ssp_base in the TCB if SHSTK is enabled

Diff:
---
 sysdeps/x86_64/dl-cet.c                     |  8 ++++++++
 sysdeps/x86_64/nptl/nptl_arch_thread_init.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/sysdeps/x86_64/dl-cet.c b/sysdeps/x86_64/dl-cet.c
index 1297c09f84..d21854924d 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 0000000000..64de1d57bb
--- /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
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-31 20:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-31 20:49 [glibc/fw/x86-shstk-backtrace] x86_64: Always initialize ssp_base in the TCB if SHSTK is enabled Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).