]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Apr 2020 14:12:06 +0000 (16:12 +0200)
commit d18b2f43b9147c8005ae0844fb445d8cc6a87e31 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c

index a0b511360a0c00749f658f26b68aa461fba7a797..05da509c706076398f7ea8e3b615a8feabb044a9 100644 (file)
@@ -1930,6 +1930,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 d602d723aaef2888ad6147623cee2b6ca8267205..8ed78b5287a3ae0ca4abb2bb777b0f01bfdf3e27 100644 (file)
@@ -6633,6 +6633,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;
 }