[RFC 0/5] aarch64: support shadow stack in clone3

Yury Khrustalev yury.khrustalev@arm.com
Tue Jun 10 15:13:15 GMT 2025


Kernel extends clone3() interface to allow specifying a shadow stack
when creating a new thread or process [1].

In this patch series we make use of this extended interface on aarch64
when GCS is available.

Request for comments.

Part of the difficulty is versioning of the clone3() syscall in terms of
the struct clone_args as discussed in [2] and that a system can support
HWCAP_GCS without supporting extended struct clone_args. In the current
patch I rely on the version of the running kernel as per the result of the
uname() syscall. This extends a similar check for SVE. Although, this works,
this mechanism may not be ideal because support for extended struct clone_args
can be back-ported to earlier versions of the kernel, not to mention what to
do if the uname() syscall fails.

Having to do an extra syscall is not ideal. It could probably be replaced
by a new (software-only) HWCAP flag, but this will need to be agreed on the
kernel side and be cross-target. Maybe there are better ways of doing this?

Regression was tested on aarch64 and no regression was found.

Corresponding Linux kernel patch is [1] and can be checked out from [3]
(based on 6.16-rc1).

This change can be tested on the FVP model as described in [4].

base commit: b15ed85c86

[1]: https://lore.kernel.org/all/20250609-clone3-shadow-stack-v17-0-8840ed97ff6f@kernel.org/
[2]: https://lore.kernel.org/lkml/aCs65ccRQtJBnZ_5@arm.com/
[3]: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/ci.git/log/?h=clone3-shadow-stack
[4]: https://inbox.sourceware.org/libc-help/aEhKdITyiwpMu7TO@arm.com/

---

Yury Khrustalev (5):
  aarch64: GCS: use internal struct in __alloc_gcs
  aarch64: check if clone3 supports shadow stack
  clone: Add clone_arg field for shadow stack
  nptl: Add libc allocated shadow stack for new threads
  aarch64: GCS: add clone3 test for shadow stack

 nptl/descr.h                                  |   7 ++
 nptl/pthread_create.c                         |  22 ++++
 sysdeps/aarch64/__alloc_gcs.c                 |  15 ++-
 sysdeps/aarch64/aarch64-gcs.h                 |  17 ++-
 sysdeps/aarch64/cpu-features.h                |   1 +
 sysdeps/aarch64/libc-shadow-stack.h           |  46 +++++++
 sysdeps/generic/libc-shadow-stack.h           |  25 ++++
 sysdeps/unix/sysv/linux/aarch64/Makefile      |   9 ++
 .../unix/sysv/linux/aarch64/cpu-features.c    |  96 ++++++++++----
 sysdeps/unix/sysv/linux/aarch64/makecontext.c |   4 +-
 .../unix/sysv/linux/aarch64/tst-gcs-clone3.c  | 118 ++++++++++++++++++
 sysdeps/unix/sysv/linux/clone-internal.c      |   7 +-
 sysdeps/unix/sysv/linux/clone3.h              |   2 +
 sysdeps/unix/sysv/linux/spawni.c              |   1 +
 14 files changed, 337 insertions(+), 33 deletions(-)
 create mode 100644 sysdeps/aarch64/libc-shadow-stack.h
 create mode 100644 sysdeps/generic/libc-shadow-stack.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-clone3.c

-- 
2.39.5



More information about the Libc-alpha mailing list