* [PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers
@ 2026-11-16 3:25 Zong Li
2026-11-16 11:59 ` Jisheng Zhang
0 siblings, 1 reply; 2+ messages in thread
From: Zong Li @ 2026-11-16 3:25 UTC (permalink / raw)
To: pjw, palmer, aou, alex, debug, samuel.holland, linux-riscv,
linux-kernel
Cc: Zong Li, Greentime Hu
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@sifive.com>
Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Zong Li <zong.li@sifive.com>
---
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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers
2026-11-16 3:25 [PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers Zong Li
@ 2026-11-16 11:59 ` Jisheng Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Jisheng Zhang @ 2026-11-16 11:59 UTC (permalink / raw)
To: Zong Li, ivanrwcm25
Cc: pjw, palmer, aou, alex, debug, samuel.holland, linux-riscv,
linux-kernel, Greentime Hu
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@gmail.com/
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@sifive.com>
> Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
> Signed-off-by: Zong Li <zong.li@sifive.com>
> ---
> 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@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 12:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 3:25 [PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers Zong Li
2026-11-16 11:59 ` Jisheng Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox