From: 黄华成 <1112433017@e.gzhu.edu.cn>
To: linux-riscv <linux-riscv@lists.infradead.org>
Cc: palmer <palmer@dabbelt.com>, pjw <pjw@kernel.org>,
aou <aou@eecs.berkeley.edu>, alex <alex@ghiti.fr>,
debug <debug@rivosinc.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
stable <stable@vger.kernel.org>
Subject: [PATCH 1/1] riscv: usercfi: bind signal shadow-stack restore to the active shadow stack
Date: Mon, 23 Nov 2026 02:17:59 +0800 [thread overview]
Message-ID: <tencent_7D0AC8F176A26AB26D61F6A8@qq.com> (raw)
hello,
Write it's for usercfi,
restore_user_shstk() reads the shadow-stack pointer from the user signal frame (sc_extdesc.ss_ptr) and validates the token found there only by the value relation token == shstk_ptr + SHSTK_ENTRY_SIZE. Nothing binds ss_ptr to the shadow-stack position the kernel recorded when the signal was delivered.
A corrupted sigframe can therefore redirect the restore to a stale but still-live token belonging to another signal context (in-bounds and genuinely valid, so the df333b72c0e1 bounds check passes); the kernel accepts it, swaps it out, and rewinds ssp to that token's position. The result is a kernel-mediated shadow-stack rewind to an attacker-chosen depth, after which sspopchk() accepts return addresses that are only valid at that historical depth - a backward-CFI bypass reachable from an ordinary memory-corruption primitive. x86 CET does not have this shape:its sigframe contains no shadow-stack pointer at all.
Bind the restore pointer to get_active_shstk(tsk), the position save_user_shstk() recorded at delivery, and fail with -EINVAL on mismatch. Valid returns are unaffected because on the happy path the frame's ss_ptr equals the active position by construction.
Verified on a fully hardened instrumented target (PIE/ASLR/canary/RELRO/NX, clang Zicfiss): the stale-token replay chain succeeds on the unpatched kernel (67/67 among completed recon rounds) and is blocked on he patched one (52/52), while normal and nested signals, sigaltstack, siglongjmp followed by a later signal, setcontext and swapcontext all behave identically on both kernels, as do the official signal kselftests.
Fixes: 66c9c713de59 ("riscv/signal: save and restore the shadow stack on a signal")
---
arch/riscv/kernel/usercfi.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c
--- a/arch/riscv/kernel/usercfi.c
+++ b/arch/riscv/kernel/usercfi.c
@@ -207,6 +207,15 @@ int restore_user_shstk(struct task_struct *tsk, unsigned long shstk_ptr)
{
unsigned long token = 0;
+ /*
+ * The frame controls ss_ptr; bind it to the kernel-recorded active
+ * shadow stack so a corrupted sigframe cannot redirect the restore
+ * at a stale but still-live token from another signal context.
+ */
+ if (shstk_ptr != get_active_shstk(tsk)) {
+ pr_info_ratelimited("%s[%d]: shadow stack ptr mismatch in %s: expected=%px, got=%px\n",
+ tsk->comm, task_pid_nr(tsk), __func__,
+ (void *)get_active_shstk(tsk),
+ (void *)shstk_ptr);
+ return -EINVAL;
+ }
+
token = amo_user_shstk((unsigned long __user *)shstk_ptr, 0);
if (token == -1)
--
2.43.0
Thanks,
Looking forward to your reply!
reply other threads:[~2026-11-22 18:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=tencent_7D0AC8F176A26AB26D61F6A8@qq.com \
--to=1112433017@e.gzhu.edu.cn \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=debug@rivosinc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=stable@vger.kernel.org \
/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®