Re: [PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers

From: Jisheng Zhang

Date: Mon Nov 16 2026 - 07:20:01 EST


On Sun, Nov 15, 2026 at 07:25:58PM -0800, Zong Li wrote:
> 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().

+ Ivan,

I think Ivan has fixed this issue in
https://lore.kernel.org/linux-riscv/20261028154315.1272705-3-ivanrwcm25@xxxxxxxxx/

Besides the issue, he also fixed another bug in riscv. The only
difference is whether set_active_shstk(p, 0) is needed or not.

And in the same series, a selftest is also added. So IMHO, we'd better
take Ivan's version.
Just FYI, arm64 has merged the fixes into linux-7.4-rc3

>
> 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
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/linux-riscv