mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jisheng Zhang <jszhang@kernel.org>
To: Zong Li <zong.li@sifive.com>, ivanrwcm25@gmail.com
Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, debug@rivosinc.com, samuel.holland@sifive.com,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Greentime Hu <greentime.hu@sifive.com>
Subject: Re: [PATCH] riscv: usercfi: Don't inherit parent shadow stack for user workers
Date: Mon, 16 Nov 2026 19:59:42 +0800	[thread overview]
Message-ID: <avrwLtiPQWedXpY_@xhacker> (raw)
In-Reply-To: <20261116032558.130928-1-zong.li@sifive.com>

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

      reply	other threads:[~2026-11-16 12:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  3:25 Zong Li
2026-11-16 11:59 ` Jisheng Zhang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avrwLtiPQWedXpY_@xhacker \
    --to=jszhang@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=debug@rivosinc.com \
    --cc=greentime.hu@sifive.com \
    --cc=ivanrwcm25@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=zong.li@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®