summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRadim Krčmář <[email protected]>2025-04-29 16:25:46 +0200
committerAnup Patel <[email protected]>2025-04-30 10:14:26 +0530
commit6b877fb53b8da84c69f0832c7f2a343239ba609e (patch)
treefa0396b2e47ea5cea2241f13cb967e9e97031c15 /lib
parent009f77a9f06bcb5a3a6252b3333171adb8c84512 (diff)
lib: sbi_hart: reset sstateen and hstateen
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 <[email protected]> Signed-off-by: Radim Krčmář <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_hart.c6
1 files changed, 6 insertions, 0 deletions
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) {