KVM: x86: Gracefully handle __vmalloc() failure during VM allocation
authorSean Christopherson <sean.j.christopherson@intel.com>
Mon, 27 Jan 2020 00:41:11 +0000 (16:41 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Mar 2020 16:57:31 +0000 (17:57 +0100)
Check the result of __vmalloc() to avoid dereferencing a NULL pointer in
the event that allocation failres.

Fixes: d1e5b0e98ea27 ("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>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c

index ad3f5b1..0455bd1 100644 (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;
 }
 
index 15ddaf8..933c72b 100644 (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;
 }