[PATCH v3 0/4] arm64, riscv: release shadow stacks on failed fork

From: Iván Ezequiel Rodriguez

Date: Wed Oct 28 2026 - 12:05:47 EST


clone3(CLONE_VM|CLONE_PIDFD) can fail in put_user() after copy_thread()
has mapped a shadow stack into the shared mm. copy_process() then calls
exit_thread(). arm64 and riscv did not implement it, so the VMA leaked.

x86 already frees via exit_thread() -> shstk_free(). Its separate TLS
leak is when copy_thread() fails after the alloc and skips exit_thread().

Changes since v2:
- Move gcs_reset_thread() into process.c (Mark Brown).
- Spell out the x86 vs arm64/riscv difference above.

v2: https://lore.kernel.org/all/cover.1792519121.git.ivanrwcm25@xxxxxxxxx/

Assisted-by: LLM


Iván Ezequiel Rodriguez (4):
arm64/gcs: release GCS on failed fork
riscv/shstk: release shadow stack on failed fork
selftests/arm64: GCS must not leak on a failed clone3
selftests/riscv: shadow stack must not leak on a failed clone3

arch/arm64/Kconfig | 1 +
arch/arm64/kernel/process.c | 16 ++
arch/riscv/Kconfig | 1 +
arch/riscv/kernel/process.c | 9 +
tools/testing/selftests/arm64/gcs/Makefile | 3 +-
.../selftests/arm64/gcs/gcs-clone-pidfd.c | 168 +++++++++++++++++
.../testing/selftests/arm64/gcs/gcs-locking.c | 20 --
tools/testing/selftests/arm64/gcs/gcs-util.h | 24 +++
tools/testing/selftests/arm64/gcs/libc-gcs.c | 20 --
tools/testing/selftests/riscv/cfi/Makefile | 5 +-
.../selftests/riscv/cfi/shstk-clone-pidfd.c | 173 ++++++++++++++++++
11 files changed, 398 insertions(+), 42 deletions(-)
create mode 100644 tools/testing/selftests/arm64/gcs/gcs-clone-pidfd.c
create mode 100644 tools/testing/selftests/riscv/cfi/shstk-clone-pidfd.c

--
2.43.0