From: Yufeng Wang Date: Tue, 17 Mar 2026 11:47:59 +0000 (+0800) Subject: riscv: kvm: add null pointer check for vector datap X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b33ab1e8c189bd0aced0d07545b0f31a459d40e;p=thirdparty%2Fkernel%2Fstable.git riscv: kvm: add null pointer check for vector datap Add WARN_ON check before accessing cntx->vector.datap in kvm_riscv_vcpu_vreg_addr() to detect potential null pointer dereferences early, consistent with the pattern used in kvm_riscv_vcpu_vector_reset(). This helps catch initialization issues where vector context allocation may have failed. Signed-off-by: Yufeng Wang Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20260317114759.53165-1-r4o5m6e8o@163.com Signed-off-by: Anup Patel --- diff --git a/arch/riscv/kvm/vcpu_vector.c b/arch/riscv/kvm/vcpu_vector.c index 5b6ad82d47be..f3f5fb665cf6 100644 --- a/arch/riscv/kvm/vcpu_vector.c +++ b/arch/riscv/kvm/vcpu_vector.c @@ -130,6 +130,7 @@ static int kvm_riscv_vcpu_vreg_addr(struct kvm_vcpu *vcpu, } else if (reg_num <= KVM_REG_RISCV_VECTOR_REG(31)) { if (reg_size != vlenb) return -EINVAL; + WARN_ON(!cntx->vector.datap); *reg_addr = cntx->vector.datap + (reg_num - KVM_REG_RISCV_VECTOR_REG(0)) * vlenb; } else {