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=1796358646; b=LyhlfQzcWCgnJx782sA5SjLGAYfQJYQ23oAk+iDJLZxVkzxPGxVnGGfhYhmga3MlPjdt h5T2WFloTOiO49NtwAhuAqjYcF+pVKQ3kHobKcmiurvLksxg7rPEFj3zJuLmq1k0LalZT 3XORRxDdyE72TYU+Om2EslZ3ffWHpCxWnx6/HdXSJXaeqQ9RH+0ewBZhN5aZ/xk8+UbPF mqefCgShzEE+KenB/k1Tq/ApCGTprUzBFA16Y11Acuvn5ynC1gqcn8/AwnWeKIn605pqB FHUk4UhJSkMzfYVbCU5lIhtJv3f65QkubGCs1BJbu+ILyo9YokurPtYmrKLKMLVZQPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796358646; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=M45uwqQLGCd/WLDik17nSQzFsllVJZpGfnAkmmBgyio=; b=HE5LrfzbJ++cy8S3EKriOR1TQfO9sBHYN/ZwZpLJOe9xWTu/0KuopbrIv8NkA9arIDKe /KkOjExa6Q1cSKIalfmn3ZYFBIIaFuQ63FWkyQMDzDAjsfoVoq89JsgeEcnoGrlil7xqk WKjlZHAlX3M3ncXTmvb5QjEbB/103wZLYYEaNBS+LGzDB4OSyjmd9MAMd5y4UmsyMW2Uo yvblJahk/cgPup8Uzdhq3KIflPrhRSVmeTf43tUb0B/zMRsjKxqsIGmH7lxss7EGtya8f 0Og6k3alXipJnArehtGiWk3/tXZPfyPNDwfx21nOfQyQOdlIflyWyy8AmLm4QNEb2ag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lau+auyq; 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 81CE6606A335 for ; Fri, 4 Dec 2026 04:30:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lau+auyq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52D581F000CE; Fri, 4 Dec 2026 04:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796358646; bh=M45uwqQLGCd/WLDik17nSQzFsllVJZpGfnAkmmBgyio=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lau+auyqhzeEDgE+YqbWi2EUNoHiBJQArvXP42xOy0KE7czpZrlNDq9B7G0PdyAKM 4uW4PZK54ILA5Rm/bUQsvmmTnA5lC1/c6SCouC5EZcUu6mAGj9NfzSq/Io0R/Pm6Fb xqTBK8rFRJ+ppEX5mJbWcFignY6V9A880LSduOGcqUGyQNJsyzYi+P2AMS0fi2aazp PTkmEDjbVGH6ZzQCb3bDrXzj5GX/8zGYRiWAa2f7KylPKdA+NInGBx0xLjIOpcgkI2 Ie2GdAvtkqX0F89nKIEicxlZXVQRvCbziUrI0kcpL+aZ5Ec3HZei35svJH2Z844IFr d5NyzzusA5ddA== From: Sasha Levin To: stable@vger.kernel.org Cc: Yunhui Cui , Jisheng Zhang , Andy Chiu , Yicong Yang , Paul Walmsley , Sasha Levin Subject: [PATCH 6.1.y] riscv: Fix SR_SUM leakage across context switches Date: Thu, 3 Dec 2026 23:30:43 -0500 Message-ID: <20261204043032.2612193-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120213-stiffly-snout-4a8b@gregkh> References: <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-Transfer-Encoding: 8bit From: Yunhui Cui [ Upstream commit 807b09be9c8f234ce758bcf43101f34e0a036b83 ] __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 [ sashal: Adjusted context: this tree lacks the scs_save_current line and names the field TASK_THREAD_STATUS_RA, so the same three-line sstatus/SR_SUM change was applied by hand. ] Signed-off-by: Sasha Levin --- arch/riscv/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 2f8bc50c3b4ab..27a28887559c7 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -503,13 +503,13 @@ ENTRY(__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_STATUS_RA(a3) /* Restore context from next->thread */ REG_L s0, TASK_THREAD_STATUS_RA(a4) - li s1, SR_SUM and s0, s0, s1 csrs CSR_STATUS, s0 REG_L ra, TASK_THREAD_RA_RA(a4) -- 2.53.0