KVM: x86: Gracefully handle __vmalloc() failure during VM allocation

Check the result of __vmalloc() to avoid dereferencing a NULL pointer in
the event that allocation failres.

Fixes: d1e5b0e98e ("kvm: Make VM ioctl do valloc for some archs")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Sean Christopherson 2020-01-26 16:41:11 -08:00 committed by Paolo Bonzini
parent 168d918f26
commit d18b2f43b9
2 changed files with 8 additions and 0 deletions

View File

@ -1949,6 +1949,10 @@ static struct kvm *svm_vm_alloc(void)
struct kvm_svm *kvm_svm = __vmalloc(sizeof(struct kvm_svm),
GFP_KERNEL_ACCOUNT | __GFP_ZERO,
PAGE_KERNEL);
if (!kvm_svm)
return NULL;
return &kvm_svm->kvm;
}

View File

@ -6684,6 +6684,10 @@ static struct kvm *vmx_vm_alloc(void)
struct kvm_vmx *kvm_vmx = __vmalloc(sizeof(struct kvm_vmx),
GFP_KERNEL_ACCOUNT | __GFP_ZERO,
PAGE_KERNEL);
if (!kvm_vmx)
return NULL;
return &kvm_vmx->kvm;
}