]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
KVM: Forbid /dev/kvm being opened by a compat task when CONFIG_KVM_COMPAT=n
authorMarc Zyngier <maz@kernel.org>
Wed, 13 Nov 2019 16:05:23 +0000 (16:05 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 13 Nov 2019 16:13:12 +0000 (17:13 +0100)
On a system without KVM_COMPAT, we prevent IOCTLs from being issued
by a compat task. Although this prevents most silly things from
happening, it can still confuse a 32bit userspace that is able
to open the kvm device (the qemu test suite seems to be pretty
mad with this behaviour).

Take a more radical approach and return a -ENODEV to the compat
task.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virt/kvm/kvm_main.c

index 524cff24a68dbc92db2a2f2ce4f880fd2d679b64..6a65ed915c7aac2c2cae0d2753d46e7967e59280 100644 (file)
@@ -124,7 +124,13 @@ static long kvm_vcpu_compat_ioctl(struct file *file, unsigned int ioctl,
 #else
 static long kvm_no_compat_ioctl(struct file *file, unsigned int ioctl,
                                unsigned long arg) { return -EINVAL; }
-#define KVM_COMPAT(c)  .compat_ioctl   = kvm_no_compat_ioctl
+
+static int kvm_no_compat_open(struct inode *inode, struct file *file)
+{
+       return is_compat_task() ? -ENODEV : 0;
+}
+#define KVM_COMPAT(c)  .compat_ioctl   = kvm_no_compat_ioctl,  \
+                       .open           = kvm_no_compat_open
 #endif
 static int hardware_enable_all(void);
 static void hardware_disable_all(void);