KVM: RISC-V: reset smstateen CSRs
authorRadim Krčmář <rkrcmar@ventanamicro.com>
Thu, 3 Apr 2025 11:25:24 +0000 (13:25 +0200)
committerAnup Patel <anup@brainfault.org>
Thu, 1 May 2025 12:56:14 +0000 (18:26 +0530)
Not resetting smstateen is a potential security hole, because VU might
be able to access state that VS does not properly context-switch.

Fixes: 81f0f314fec9 ("RISCV: KVM: Add sstateen0 context save/restore")
Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com>
Link: https://lore.kernel.org/r/20250403112522.1566629-8-rkrcmar@ventanamicro.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vcpu.c

index 60d684c76c58731a62e7ed3eab286ff713b3daae..02635bac91f175989fa7a4430542483816d461f9 100644 (file)
@@ -77,6 +77,8 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu)
        memcpy(cntx, reset_cntx, sizeof(*cntx));
        spin_unlock(&vcpu->arch.reset_cntx_lock);
 
+       memset(&vcpu->arch.smstateen_csr, 0, sizeof(vcpu->arch.smstateen_csr));
+
        kvm_riscv_vcpu_fp_reset(vcpu);
 
        kvm_riscv_vcpu_vector_reset(vcpu);