Skip to content

Commit 1d57ab4

Browse files
osamakadergregkh
authored andcommitted
riscv: kvm: fix vector context allocation leak
commit b7c958d upstream. When the second kzalloc (host_context.vector.datap) fails in kvm_riscv_vcpu_alloc_vector_context, the first allocation (guest_context.vector.datap) is leaked. Free it before returning. Fixes: 0f4b825 ("riscv: KVM: Add vector lazy save/restore support") Cc: stable@vger.kernel.org Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com> Reviewed-by: Andy Chiu <andybnac@gmail.com> Link: https://lore.kernel.org/r/20260316151612.13305-1-osama.abdelkader@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 615d9d2 commit 1d57ab4

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

arch/riscv/kvm/vcpu_vector.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ int kvm_riscv_vcpu_alloc_vector_context(struct kvm_vcpu *vcpu)
8080
return -ENOMEM;
8181

8282
vcpu->arch.host_context.vector.datap = kzalloc(riscv_v_vsize, GFP_KERNEL);
83-
if (!vcpu->arch.host_context.vector.datap)
83+
if (!vcpu->arch.host_context.vector.datap) {
84+
kfree(vcpu->arch.guest_context.vector.datap);
85+
vcpu->arch.guest_context.vector.datap = NULL;
8486
return -ENOMEM;
87+
}
8588

8689
return 0;
8790
}

0 commit comments

Comments
 (0)