KVM: s390: Check kvm pointer when testing KVM_CAP_S390_HPAGE_1M
authorJean-Philippe Brucker <jean-philippe@linaro.org>
Fri, 19 Apr 2024 16:07:24 +0000 (17:07 +0100)
committerChristian Borntraeger <borntraeger@linux.ibm.com>
Thu, 2 May 2024 07:41:38 +0000 (09:41 +0200)
KVM allows issuing the KVM_CHECK_EXTENSION ioctl either on the /dev/kvm
fd or the VM fd. In the first case, kvm_vm_ioctl_check_extension() is
called with kvm==NULL. Ensure we don't dereference the pointer in that
case.

Fixes: 40ebdb8e59df ("KVM: s390: Make huge pages unavailable in ucontrol VMs")
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Message-ID: <20240419160723.320910-2-jean-philippe@linaro.org>
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
arch/s390/kvm/kvm-s390.c

index 5147b943a864a641fcf5d87fed39eb33f4590bea..7721eb522f43dd2ab40680e38edc7946854dfc32 100644 (file)
@@ -587,7 +587,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
                break;
        case KVM_CAP_S390_HPAGE_1M:
                r = 0;
-               if (hpage && !kvm_is_ucontrol(kvm))
+               if (hpage && !(kvm && kvm_is_ucontrol(kvm)))
                        r = 1;
                break;
        case KVM_CAP_S390_MEM_OP: