From 6b877fb53b8da84c69f0832c7f2a343239ba609e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Date: Tue, 29 Apr 2025 16:25:46 +0200 Subject: [PATCH] lib: sbi_hart: reset sstateen and hstateen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not resetting sstateen is a potential security hole, because U might be able to access state that S does not properly context-switch. Similar for hstateen with VS and HS. Reviewed-by: Anup Patel Signed-off-by: Radim Krčmář Link: https://lore.kernel.org/r/20250429142549.3673976-6-rkrcmar@ventanamicro.com Signed-off-by: Anup Patel --- lib/sbi/sbi_hart.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 5ea7328a..bdf66ef7 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -111,6 +111,12 @@ static void mstatus_init(struct sbi_scratch *scratch) mstateen_val &= ~SMSTATEEN0_CTR; csr_write64(CSR_MSTATEEN0, mstateen_val); + + if (misa_extension('S')) + csr_write(CSR_SSTATEEN0, 0); + + if (misa_extension('H')) + csr_write64(CSR_HSTATEEN0, (uint64_t)0); } if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {