[PATCH v3 1/3] clone: Add clone_arg field for shadow stack
Yury Khrustalev
yury.khrustalev@arm.com
Tue Sep 16 12:27:55 GMT 2025
Corresponding change in the kernel was proposed in
https://lore.kernel.org/all/20250916-clone3-shadow-stack-v21-0-910493527013@kernel.org/
---
sysdeps/unix/sysv/linux/clone-internal.c | 7 +++++--
sysdeps/unix/sysv/linux/clone3.h | 2 ++
sysdeps/unix/sysv/linux/spawni.c | 1 +
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/clone-internal.c b/sysdeps/unix/sysv/linux/clone-internal.c
index 9a1f27d017..a61645cad2 100644
--- a/sysdeps/unix/sysv/linux/clone-internal.c
+++ b/sysdeps/unix/sysv/linux/clone-internal.c
@@ -27,6 +27,7 @@
#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
#define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */
#define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */
+#define CLONE_ARGS_SIZE_VER3 96 /* sizeof fourth published struct */
#define sizeof_field(TYPE, MEMBER) sizeof ((((TYPE *)0)->MEMBER))
#define offsetofend(TYPE, MEMBER) \
@@ -40,8 +41,10 @@ _Static_assert (offsetofend (struct clone_args, set_tid_size) == CLONE_ARGS_SIZE
"offsetofend (struct clone_args, set_tid_size) != CLONE_ARGS_SIZE_VER1");
_Static_assert (offsetofend (struct clone_args, cgroup) == CLONE_ARGS_SIZE_VER2,
"offsetofend (struct clone_args, cgroup) != CLONE_ARGS_SIZE_VER2");
-_Static_assert (sizeof (struct clone_args) == CLONE_ARGS_SIZE_VER2,
- "sizeof (struct clone_args) != CLONE_ARGS_SIZE_VER2");
+_Static_assert (offsetofend (struct clone_args, shadow_stack_token) == CLONE_ARGS_SIZE_VER3,
+ "offsetofend (struct clone_args, shadow_stack) != CLONE_ARGS_SIZE_VER3");
+_Static_assert (sizeof (struct clone_args) == CLONE_ARGS_SIZE_VER3,
+ "sizeof (struct clone_args) != CLONE_ARGS_SIZE_VER3");
int
__clone_internal_fallback (struct clone_args *cl_args,
diff --git a/sysdeps/unix/sysv/linux/clone3.h b/sysdeps/unix/sysv/linux/clone3.h
index 847ca96d0d..d964a84fa0 100644
--- a/sysdeps/unix/sysv/linux/clone3.h
+++ b/sysdeps/unix/sysv/linux/clone3.h
@@ -61,6 +61,8 @@ struct clone_args
__aligned_uint64_t set_tid_size;
/* File descriptor for target cgroup of child (since Linux 5.7). */
__aligned_uint64_t cgroup;
+ /* Shadow stack support (since Linux 6.17). */
+ __aligned_uint64_t shadow_stack_token;
};
#endif /* clone3.h */
diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
index bc8476ff11..b80fb0ca20 100644
--- a/sysdeps/unix/sysv/linux/spawni.c
+++ b/sysdeps/unix/sysv/linux/spawni.c
@@ -412,6 +412,7 @@ __spawnix (int *pid, const char *file,
/* This is require for clone fallback, where pidfd is returned
on parent_tid. */
.parent_tid = use_pidfd ? (uintptr_t) &args.pidfd : 0,
+ .shadow_stack_token = 0,
};
#ifdef HAVE_CLONE3_WRAPPER
args.use_clone3 = true;
--
2.47.3
More information about the Libc-alpha
mailing list