]> git.dujemihanovic.xyz Git - linux.git/commitdiff
KVM: x86: Fix potential fput on a null source_kvm_file
authorColin Ian King <colin.king@canonical.com>
Fri, 30 Apr 2021 17:03:03 +0000 (18:03 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 3 May 2021 15:25:40 +0000 (11:25 -0400)
The fget can potentially return null, so the fput on the error return
path can cause a null pointer dereference. Fix this by checking for
a null source_kvm_file before doing a fput.

Addresses-Coverity: ("Dereference null return")
Fixes: 54526d1fd593 ("KVM: x86: Support KVM VMs sharing SEV context")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Message-Id: <20210430170303.131924-1-colin.king@canonical.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/sev.c

index 1356ee095cd5532e64cade9bb449bc8fc7302431..8b11c711a0e40545a52483636ad3991f8b5eb24f 100644 (file)
@@ -1764,7 +1764,8 @@ e_mirror_unlock:
 e_source_unlock:
        mutex_unlock(&source_kvm->lock);
 e_source_put:
-       fput(source_kvm_file);
+       if (source_kvm_file)
+               fput(source_kvm_file);
        return ret;
 }