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

Anup Patel anup at brainfault.org
Mon Apr 28 05:27:41 PDT 2025


On Tue, Apr 15, 2025 at 7:00 PM Radim Krčmář <rkrcmar at ventanamicro.com> wrote:
>
> 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>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Regards,
Anup

> ---
>  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
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list