From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221348; b=IxTJbpzbA/8FLtLg2EgM/JGFNlWtn7rXoaDkLDYOArIZk7ayzpxs5ZcJNXcG2Xwct++3 Y3/sDAxLCseJIkNgtzruDJx7IKABS+ouaQ3DVVB2UnkrMsnRoRvjaXuy2+Ry8nhCIgEQE DJTKAzI+OgFGx95RxnllHlo8VjbgR4+kDuHju8NKh3z5e6eBbsnxwuZxlAlDs3PBAbJtY W7yXGAyokC/wwej9IAcYNMlGzcXM//fxRRR1l72RyJCNRz9ptYrEYrf2K5y9RhYGLBqCt TXLRBntmQziS1A2j5IG4AWCVsNi5Qkwz1lBz6NIA45HbIY22+h0Hl/8NcaNVaiqgE0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221348; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=Xrdra8dGtKBlY2MXLu1HAnrnvwXSf9fKdj+jVNSVjjU=; b=F1S1t01hrWcm+hBLcw5cKqW0/gcIu0ymMcAamBvnAg7xvf0oc6Qp7eHXhgNq8EPHGYL6 2fo75TzQdmCoeOm+3/UP0FDXDDOQbPtakmITw4QwBL84CTx8AsApjR39kwBOzhuq0aoYk EvXjulwyPGeAAF/SQ4YQlx93n/Ikvq5YDbMmsth8P7x/0DXX5uJ3c5GYv3wzAN6REb9I+ +FrnGK1+mBpMKS5lF8orTfjBmBhYA4PpqjAxDaSk8hHaLbf4Y7H1M1gFF0cNOSxGApWew sJOxEnPPScK4k9DAu6J7+BN71yAU9YY94mWwdsUQymdlXRdlNdw424QF1S34XBACgEA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=atuehK0s; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8F82606A31A for ; Wed, 2 Dec 2026 14:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=atuehK0s Received: by smtp.kernel.org (Postfix) with ESMTPSA id A78941F00897; Wed, 2 Dec 2026 14:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221348; bh=Xrdra8dGtKBlY2MXLu1HAnrnvwXSf9fKdj+jVNSVjjU=; h=Subject:To:Cc:From:Date; b=atuehK0sE/B/+Iy/orYED6Fa+0FoyzWoYfn6MISytHYTEuTnpetAnE2YHYhb7cdof H7J95M01Tzo3EnNC4J7yX2BqcGxLV1tpuDDIyv+GgQzdkFlvNA/SrhDhdKSHQPm8wT BEP0F0r72YRLOATGwMuEbYQGPYBSFNg1gT48VcH8= Subject: FAILED: patch "[PATCH] riscv: Fix SR_SUM leakage across context switches" failed to apply to 6.1-stable tree To: cuiyunhui@bytedance.com,jszhang@kernel.org,pjw@kernel.org,tchiu@tenstorrent.com,yang.yicong@picoheart.com Cc: From: Date: Wed, 02 Dec 2026 14:41:13 +0100 Message-ID: <2026120213-stiffly-snout-4a8b@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.1-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 . 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.1.y git checkout FETCH_HEAD git cherry-pick -x 807b09be9c8f234ce758bcf43101f34e0a036b83 # git commit -s git send-email --to '' --in-reply-to '2026120213-stiffly-snout-4a8b@gregkh' --subject-prefix 'PATCH 6.1.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 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 Reviewed-by: Jisheng Zhang Reviewed-by: Andy Chiu Reviewed-by: Yicong Yang Link: https://patch.msgid.link/20261022083212.84721-1-cuiyunhui@bytedance.com Signed-off-by: Paul Walmsley 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)