Skip to contentSkip to conversation

KVM: s390: Check kvm pointer when testing KVM_CAP_S390_HPAGE_1M

PATCH Applied Jean-Philippe Brucker 3 participants 3 messages Apr 19, 2024 – Apr 22, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: s390: Check kvm pointer when testing KVM_CAP_S390_HPAGE_1M

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")

---
Only build-tested

---
 arch/s390/kvm/kvm-s390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 5147b943a864a..7721eb522f43d 100644
@@ -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:
Signature · 1 line
2.44.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Fri, 19 Apr 2024 17:07:24 +0100 Jean-Philippe Brucker…

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")
Quoted 19 lines

---
Only build-tested

---
 arch/s390/kvm/kvm-s390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 5147b943a864a..7721eb522f43d 100644
@@ -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:
maintainer Reviewed-by on v1 1/1 Applied
#2 lore raw
In reply to Jean-Philippe Brucker

Am 19.04.24 um 18:07 schrieb Jean-Philippe Brucker:

Quoted 7 lines

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")

thanks applied.

Quoted 19 lines

---
Only build-tested

---
  arch/s390/kvm/kvm-s390.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 5147b943a864a..7721eb522f43d 100644
@@ -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: