[PATCH 3/8] lib: sbi_hart: reset hstatus

Radim Krčmář rkrcmar at ventanamicro.com
Tue Apr 15 06:19:04 PDT 2025


hstatus.HU must be cleared, because U-mode could otherwise use the
HLS/HSV instructions.  This would allow U-mode to read physical memory
directly if vgatp and vsatp was 0.

The remaining fields don't seem like a security vulnerability now, but
clearing the whole CSR is not an issue, so do that be safe.

Signed-off-by: Radim Krčmář <rkrcmar at ventanamicro.com>
---
 lib/sbi/sbi_hart.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 2d9ee60fd36c..b66b89f6bc51 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -85,6 +85,9 @@ static void mstatus_init(struct sbi_scratch *scratch)
 #endif
 	}
 
+	if (misa_extension('H'))
+		csr_write(CSR_HSTATUS, 0);
+
 	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMSTATEEN)) {
 		mstateen_val = csr_read64(CSR_MSTATEEN0);
 		mstateen_val |= SMSTATEEN_STATEN;
-- 
2.48.1




More information about the opensbi mailing list