From: <gregkh@linuxfoundation.org>
To: cuiyunhui@bytedance.com,jszhang@kernel.org,pjw@kernel.org,tchiu@tenstorrent.com,yang.yicong@picoheart.com
Cc: <stable@vger.kernel.org>
Subject: FAILED: patch "[PATCH] riscv: Fix SR_SUM leakage across context switches" failed to apply to 6.6-stable tree
Date: Wed, 02 Dec 2026 14:41:13 +0100 [thread overview]
Message-ID: <2026120213-mortuary-lying-96d8@gregkh> (raw)
The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 807b09be9c8f234ce758bcf43101f34e0a036b83
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120213-mortuary-lying-96d8@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 807b09be9c8f234ce758bcf43101f34e0a036b83 Mon Sep 17 00:00:00 2001
From: Yunhui Cui <cuiyunhui@bytedance.com>
Date: Thu, 22 Oct 2026 16:32:12 +0800
Subject: [PATCH] riscv: Fix SR_SUM leakage across context switches
__switch_to() saves the sstatus value of prev and restores the SR_SUM bit
of next with csrs. However, csrs only sets bits. If prev has SR_SUM set
and next has SR_SUM clear in its saved state, the old SR_SUM bit remains
set in sstatus.
This lets next run with user memory access enabled even though its saved
SR_SUM state is clear.
Use csrrc to save the sstatus value of prev and clear SR_SUM from the
live CSR before restoring the saved SR_SUM state of next. This keeps
prev's SR_SUM state intact, while preventing it from leaking to next.
Fixes: 788aa64c01f1 ("riscv: save the SR_SUM status over switches")
Cc: stable@vger.kernel.org
Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
Reviewed-by: Andy Chiu <tchiu@tenstorrent.com>
Reviewed-by: Yicong Yang <yang.yicong@picoheart.com>
Link: https://patch.msgid.link/20261022083212.84721-1-cuiyunhui@bytedance.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 61b7a7716697..628b85e3915a 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -443,15 +443,15 @@ SYM_FUNC_START(__switch_to)
REG_S s10, TASK_THREAD_S10_RA(a3)
REG_S s11, TASK_THREAD_S11_RA(a3)
- /* save the user space access flag */
- csrr s0, CSR_STATUS
+ /* Save and clear the user space access flag. */
+ li s1, SR_SUM
+ csrrc s0, CSR_STATUS, s1
REG_S s0, TASK_THREAD_SUM_RA(a3)
/* Save the kernel shadow call stack pointer */
scs_save_current
/* Restore context from next->thread */
REG_L s0, TASK_THREAD_SUM_RA(a4)
- li s1, SR_SUM
and s0, s0, s1
csrs CSR_STATUS, s0
REG_L ra, TASK_THREAD_RA_RA(a4)
reply other threads:[~2026-12-02 14:22 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=2026120213-mortuary-lying-96d8@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=cuiyunhui@bytedance.com \
--cc=jszhang@kernel.org \
--cc=pjw@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tchiu@tenstorrent.com \
--cc=yang.yicong@picoheart.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.