Skip to content

Commit 250f253

Browse files
willdeaconoupton
authored andcommitted
KVM: arm64: Tear down vGIC on failed vCPU creation
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]>
1 parent d766d87 commit 250f253

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
@@ -466,7 +466,11 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
466466
if (err)
467467
return err;
468468

469-
return kvm_share_hyp(vcpu, vcpu + 1);
469+
err = kvm_share_hyp(vcpu, vcpu + 1);
470+
if (err)
471+
kvm_vgic_vcpu_destroy(vcpu);
472+
473+
return err;
470474
}
471475

472476
void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)