[PATCH v6 12/23] aarch64: Enable GCS in static linked exe
Yury Khrustalev
yury.khrustalev@arm.com
Thu Dec 12 14:37:38 GMT 2024
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Use the ARCH_SETUP_TLS hook to enable GCS in the static linked case.
The system call must be inlined and then GCS is enabled on a top
level stack frame that does not return and has no exception handlers
above it.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
---
sysdeps/unix/sysv/linux/aarch64/libc-start.h | 44 ++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 sysdeps/unix/sysv/linux/aarch64/libc-start.h
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-start.h b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
new file mode 100644
index 0000000000..ea6580fca6
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
@@ -0,0 +1,44 @@
+/* AArch64 definitions for libc main startup.
+ 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/>. */
+
+#ifndef _LIBC_START_H
+#define _LIBC_START_H
+
+#ifndef SHARED
+
+# ifndef PR_SET_SHADOW_STACK_STATUS
+# define PR_SET_SHADOW_STACK_STATUS 75
+# endif
+
+/* Must be on a top-level stack frame that does not return. */
+static inline void __attribute__((always_inline))
+aarch64_libc_setup_tls (void)
+{
+ __libc_setup_tls ();
+
+ uint64_t s = GL(dl_aarch64_gcs);
+ if (s != 0)
+ INLINE_SYSCALL_CALL (prctl, PR_SET_SHADOW_STACK_STATUS, s, 0, 0, 0);
+}
+
+# define ARCH_SETUP_IREL() apply_irel ()
+# define ARCH_SETUP_TLS() aarch64_libc_setup_tls ()
+# define ARCH_APPLY_IREL()
+#endif /* ! SHARED */
+
+#endif /* _LIBC_START_H */
--
2.39.5
More information about the Libc-alpha
mailing list