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=1796358376; b=RaUIvdr/5n4OCCKK6eCzVafVvnI+bLGwZqxnttl+6h9GkodEuZEPmuH46Tn/RAWmQ1Ey O2FpDbJuIjKG5f6NhH+8v7k734JB6/rrqbCZoCYN+72q4osuUykbq5MMyQ74YRPjmdEXN Mh337oT4WJhd5XT3udPviykJiecaYWK79doSOUhDoYaFw9HOqXkN3+dDBHobLj1lQgO6P untVViTY8xtPprqZBkZuWxRhxBQXLswBoEnQWhC5b75qzo7L9QRxmuRmoke7DHm7rsJlV y3HxV484UFfRLFu52sdAzvvpo3zt6+WJKJIpHAF8y/AY1OFF8D0v92+j1XzLjqZvRGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796358376; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ZGMQ2YAyuKjfouW1EvEgj/ZDuD7kjGZ4ZKU5Xvv75Rw=; b=fUoc2C3EpifxuTiaa5k7yXJI9UgjPrbjNfBkeDTpy67mqUNEIeOYpMwYwaMjZJSaqQmi iMsQCV3xOv4W9VHA0LyvoUkUB6ecrpkH8YYQ9dbE35MrC1eXykdmftkht9bxS65zW/vhD SBFU0BDYP4wZDRwrjySPkL0moatk/yB61wTplvLO7occmWVPZ9ejzIKMpHA6nGqeVVVNj NalKztO3a5f80NS4tcxIVlL9r0YIOzFtrol/oYwNftcLWOeHVbbssa7p9hd6caurA2Fqj qi3dOsKkemEOPTMTlOEDDQW41pUWzNCyzzQPfPXoHWKolUUwTL8GpjPpLFYjD06OUvA== 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=ZEWyXQYH; 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 DBFFF606A689 for ; Fri, 4 Dec 2026 04:26:16 +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=ZEWyXQYH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 967331F000C2; Fri, 4 Dec 2026 04:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796358376; bh=ZGMQ2YAyuKjfouW1EvEgj/ZDuD7kjGZ4ZKU5Xvv75Rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZEWyXQYHt/Y6OAR20+ZvY7Zk24Of6oC92mxfE5V86UKDGrQoDJoO7Ena+L6DMWkSg gqvyDd0ve5gbItwaydiPfKBBOFExfGcBPblti69lvq5ZTNe4POwsGjuc1neoP86OAf gFYK9Vg6vqyZ+n5vrJdevaTBtkq2mZPAfw1duHdLVzqK3n4c5Qb3YkknnhYewpUP80 fOmRxOrA251lByQNv0orNZ3VgxxIDLB7wspSbsyB4+MTMwMZD0I6grBtxOyxyqF/Oe Ylfe1lAo+c8X/LhDrDKOtxiCQGFaU82P+3o86g1bXkqQMciKuGSPwcgH7XBbeITEqv VUp0keQlixUPQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Yunhui Cui , Jisheng Zhang , Andy Chiu , Yicong Yang , Paul Walmsley , Sasha Levin Subject: [PATCH 6.6.y] riscv: Fix SR_SUM leakage across context switches Date: Thu, 3 Dec 2026 23:26:14 -0500 Message-ID: <20261204042602.2598716-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120213-mortuary-lying-96d8@gregkh> References: <2026120213-mortuary-lying-96d8@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: Adapted to the older layout by keeping the existing SR_SUM mask and swapping the save-side csrr for csrrc, leaving the restore side unchanged and using the older TASK_THREAD_STATUS_RA name. ] Signed-off-by: Sasha Levin --- arch/riscv/kernel/entry.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index b9d321fb1f754..f25ab9aed2209 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -257,9 +257,9 @@ 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 */ + /* Save and clear the user space access flag. */ li s0, SR_SUM - csrr s1, CSR_STATUS + csrrc s1, CSR_STATUS, s0 and s1, s1, s0 REG_S s1, TASK_THREAD_STATUS_RA(a3) -- 2.53.0