Skip to content

Commit b9876e6

Browse files
Marc Zyngierbonzini
authored andcommitted
KVM: Forbid /dev/kvm being opened by a compat task when CONFIG_KVM_COMPAT=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 <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6cbee2b commit b9876e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

virt/kvm/kvm_main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ static long kvm_vcpu_compat_ioctl(struct file *file, unsigned int ioctl,
124124
#else
125125
static long kvm_no_compat_ioctl(struct file *file, unsigned int ioctl,
126126
unsigned long arg) { return -EINVAL; }
127-
#define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl
127+
128+
static int kvm_no_compat_open(struct inode *inode, struct file *file)
129+
{
130+
return is_compat_task() ? -ENODEV : 0;
131+
}
132+
#define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl, \
133+
.open = kvm_no_compat_open
128134
#endif
129135
static int hardware_enable_all(void);
130136
static void hardware_disable_all(void);

0 commit comments

Comments
 (0)