Skip to content

Commit

Permalink
KVM: Forbid /dev/kvm being opened by a compat task when CONFIG_KVM_CO…
Browse files Browse the repository at this point in the history
…MPAT=n

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>
  • Loading branch information
Marc Zyngier authored and bonzini committed Nov 13, 2019
1 parent 6cbee2b commit b9876e6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b9876e6

Please sign in to comment.