Skip to contentSkip to conversation

KVM: arm64: Don't WARN on an unknown VM ioctl in protected mode

PATCH Applied Fuad Tabba 3 participants 3 messages Sep 14 – Sep 15

Subsystems (2)
lore
Share & tools
lore

Fuad Tabba

author reviewer
#0 lore raw

PATCH 1/1 KVM: arm64: Don't WARN on an unknown VM ioctl in protected mode

kvm_pkvm_ioctl_allowed() WARNs when kvm_get_cap_for_kvm_ioctl() doesn't find the ioctl number in vm_ioctl_caps[], and kvm_arch_vm_ioctl() calls it for every number the generic code doesn't handle, so ioctl(vm_fd, 0xdeadbeef) from userspace taints a pKVM host and panics it under panic_on_warn. The lookup is fed userspace input: return false, and userspace gets the -EINVAL kvm_arch_vm_ioctl() returns for that number on a host without pKVM.

Fixes b12b3b04f6ba0 ("KVM: arm64: Check whether a VM IOCTL is allowed in pKVM")
---
 arch/arm64/include/asm/kvm_pkvm.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/include/asm/kvm_pkvm.h +1 -2
index beea00e693a0a..cad60569f0619 100644
@@ -65,8 +65,7 @@ static inline bool kvm_pkvm_ioctl_allowed(struct kvm *kvm, unsigned int ioctl)
 	int r;
 
 	r = kvm_get_cap_for_kvm_ioctl(ioctl, &ext);
-
-	if (WARN_ON_ONCE(r < 0))
+	if (r < 0)
 		return false;
 
 	return kvm_pkvm_ext_allowed(kvm, ext);
Signature · 1 line
2.39.5
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Fuad Tabba

kvm_pkvm_ioctl_allowed() WARNs when kvm_get_cap_for_kvm_ioctl() doesn't find the ioctl number in vm_ioctl_caps[], and kvm_arch_vm_ioctl() calls it for every number the generic code doesn't handle, so ioctl(vm_fd, 0xdeadbeef) from userspace taints a pKVM host and panics it under panic_on_warn. The lookup is fed userspace input: return false, and userspace gets the -EINVAL kvm_arch_vm_ioctl() returns for that number on a host without pKVM.

Fixes b12b3b04f6ba0 ("KVM: arm64: Check whether a VM IOCTL is allowed in pKVM")

I hit this myself ;-) and had a patch in my series. Thanks for posting this

Quoted 18 lines
---
  arch/arm64/include/asm/kvm_pkvm.h | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/include/asm/kvm_pkvm.h +1 -2
index beea00e693a0a..cad60569f0619 100644
@@ -65,8 +65,7 @@ static inline bool kvm_pkvm_ioctl_allowed(struct kvm *kvm, unsigned int ioctl)
  	int r;
 
  	r = kvm_get_cap_for_kvm_ioctl(ioctl, &ext);
-
-	if (WARN_ON_ONCE(r < 0))
+	if (r < 0)
  		return false;
 
  	return kvm_pkvm_ext_allowed(kvm, ext);
maintainer Applied
#2 lore raw
In reply to Fuad Tabba
Quoted 9 lines · Fuad Tabba

kvm_pkvm_ioctl_allowed() WARNs when kvm_get_cap_for_kvm_ioctl() doesn't find the ioctl number in vm_ioctl_caps[], and kvm_arch_vm_ioctl() calls it for every number the generic code doesn't handle, so ioctl(vm_fd, 0xdeadbeef) from userspace taints a pKVM host and panics it under panic_on_warn. The lookup is fed userspace input: return false, and userspace gets the -EINVAL kvm_arch_vm_ioctl() returns for that number on a host without pKVM.

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Don't WARN on an unknown VM ioctl in protected mode

      https://git.kernel.org/kvmarm/kvmarm/c/49d9d295d69d

--
Best,
Oliver