[PATCH v2 1/3] clone: Add clone_arg field for shadow stack
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Aug 26 17:57:05 GMT 2025
On 07/07/25 09:47, Yury Khrustalev wrote:
> ---
> 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");
>
It seems to be in sync with the latest v19 version [1], which I take it
will be included without further change in ABI.
We will need to wait until is in in Linus tree and it would be good to
add the commit id on patch description.
[1] https://lkml.org/lkml/2025/8/19/1552
> 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..3797e018bf 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.16). */
> + __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 eca1a84254..5f6b0dd19b 100644
> --- a/sysdeps/unix/sysv/linux/spawni.c
> +++ b/sysdeps/unix/sysv/linux/spawni.c
> @@ -415,6 +415,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;
More information about the Libc-alpha
mailing list