]> 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 08:48:48 +0000 (10:48 +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.c

index cc8f3b41a1b2e68de6308963e404ab5dcf1567b2..df2274414640e21d4333c5f3b89909a6b17c99aa 100644 (file)
@@ -1917,6 +1917,10 @@ static void __unregister_enc_region_locked(struct kvm *kvm,
 static struct kvm *svm_vm_alloc(void)
 {
        struct kvm_svm *kvm_svm = vzalloc(sizeof(struct kvm_svm));
+
+       if (!kvm_svm)
+               return NULL;
+
        return &kvm_svm->kvm;
 }
 
index 1ad72af1726847b64f017961abb96fbbf220d6e1..47501e3b0ca0f0bcfecf0b81843d643be5276f8c 100644 (file)
@@ -10986,6 +10986,10 @@ STACK_FRAME_NON_STANDARD(vmx_vcpu_run);
 static struct kvm *vmx_vm_alloc(void)
 {
        struct kvm_vmx *kvm_vmx = vzalloc(sizeof(struct kvm_vmx));
+
+       if (!kvm_vmx)
+               return NULL;
+
        return &kvm_vmx->kvm;
 }