Skip to content

Commit 3c0ba05

Browse files
MiaoheLinbonzini
authored andcommitted
KVM: x86: fix memoryleak in kvm_arch_vcpu_create()
When allocating memory for mci_ctl2_banks fails, KVM doesn't release mce_banks leading to memoryleak. Fix this issue by calling kfree() for it when kcalloc() fails. Fixes: 281b527 ("KVM: x86: Add emulation for MSR_IA32_MCx_CTL2 MSRs.") Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> Message-Id: <20220901122300.22298-1-linmiaohe@huawei.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0204750 commit 3c0ba05

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11580,7 +11580,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
1158011580
vcpu->arch.mci_ctl2_banks = kcalloc(KVM_MAX_MCE_BANKS, sizeof(u64),
1158111581
GFP_KERNEL_ACCOUNT);
1158211582
if (!vcpu->arch.mce_banks || !vcpu->arch.mci_ctl2_banks)
11583-
goto fail_free_pio_data;
11583+
goto fail_free_mce_banks;
1158411584
vcpu->arch.mcg_cap = KVM_MAX_MCE_BANKS;
1158511585

1158611586
if (!zalloc_cpumask_var(&vcpu->arch.wbinvd_dirty_mask,
@@ -11634,7 +11634,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
1163411634
fail_free_mce_banks:
1163511635
kfree(vcpu->arch.mce_banks);
1163611636
kfree(vcpu->arch.mci_ctl2_banks);
11637-
fail_free_pio_data:
1163811637
free_page((unsigned long)vcpu->arch.pio_data);
1163911638
fail_free_lapic:
1164011639
kvm_free_lapic(vcpu);

0 commit comments

Comments
 (0)