Skip to content

Commit c322789

Browse files
willdeacongregkh
authored andcommitted
KVM: arm64: Tear down vGIC on failed vCPU creation
commit 250f253 upstream. If kvm_arch_vcpu_create() fails to share the vCPU page with the hypervisor, we propagate the error back to the ioctl but leave the vGIC vCPU data initialised. Note only does this leak the corresponding memory when the vCPU is destroyed but it can also lead to use-after-free if the redistributor device handling tries to walk into the vCPU. Add the missing cleanup to kvm_arch_vcpu_create(), ensuring that the vGIC vCPU structures are destroyed on error. Cc: <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Quentin Perret <[email protected]> Signed-off-by: Will Deacon <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 20c105f commit c322789

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/arm64/kvm/arm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,11 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
493493
if (err)
494494
return err;
495495

496-
return kvm_share_hyp(vcpu, vcpu + 1);
496+
err = kvm_share_hyp(vcpu, vcpu + 1);
497+
if (err)
498+
kvm_vgic_vcpu_destroy(vcpu);
499+
500+
return err;
497501
}
498502

499503
void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)