[PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers
From: Zong Li
Date: Sun Nov 15 2026 - 22:26:14 EST
User-space background workers created through the copy_thread() args->fn
path (such as io_uring io-wq/SQPOLL threads and vhost workers) share the
parent's memory space (CLONE_VM) but never return to userspace.
Currently, these workers inherit the parent's user_cfi_state bookkeeping
via dup_task_struct() (e.g., enabling shadow stack and pointing to the
parent's live shadow stack base). When such a worker exits, mm_release()
invokes shstk_release(), which incorrectly executes vm_munmap() on the
parent's active user shadow stack. This triggers a fatal SIGSEGV
(SEGV_MAPERR followed by SI_KERNEL) in the parent process during its next
function return check (sspopchk).
Fix this by explicitly clearing the inherited shadow stack bookkeeping
(setting base and active state to 0) in the user worker branch of
copy_thread().
Fixes: 61a0200211d3 ("riscv: Implement arch-agnostic shadow stack prctls")
Co-developed-by: Greentime Hu <greentime.hu@xxxxxxxxxx>
Signed-off-by: Greentime Hu <greentime.hu@xxxxxxxxxx>
Signed-off-by: Zong Li <zong.li@xxxxxxxxxx>
---
arch/riscv/kernel/process.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 34c1d498d1ca..4bc95acc5462 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -261,6 +261,15 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
p->thread.s[0] = (unsigned long)args->fn;
p->thread.s[1] = (unsigned long)args->fn_arg;
p->thread.ra = (unsigned long)ret_from_fork_kernel_asm;
+
+ /*
+ * User workers (io_uring io-wq/SQPOLL, vhost) share the parent's mm
+ * but never return to userspace. Don't inherit the parent's shadow
+ * stack bookkeeping, otherwise shstk_release() on their exit would
+ * vm_munmap() the parent's live shadow stack.
+ */
+ set_shstk_base(p, 0, 0);
+ set_active_shstk(p, 0);
} else {
/* allocate new shadow stack if needed. In case of CLONE_VM we have to */
ssp = shstk_alloc_thread_stack(p, args);
--
2.43.7