Skip to content

Commit 2ea75be

Browse files
dmatlackbonzini
authored andcommitted
kvm: don't take vcpu mutex for obviously invalid vcpu ioctls
vcpu ioctls can hang the calling thread if issued while a vcpu is running. However, invalid ioctls can happen when userspace tries to probe the kind of file descriptors (e.g. isatty() calls ioctl(TCGETS)); in that case, we know the ioctl is going to be rejected as invalid anyway and we can fail before trying to take the vcpu mutex. This patch does not change functionality, it just makes invalid ioctls fail faster. Cc: stable@vger.kernel.org Signed-off-by: David Matlack <dmatlack@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 234b239 commit 2ea75be

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎virt/kvm/kvm_main.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
#include <asm/processor.h>
5454
#include <asm/io.h>
55+
#include <asm/ioctl.h>
5556
#include <asm/uaccess.h>
5657
#include <asm/pgtable.h>
5758

@@ -2032,6 +2033,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
20322033
if (vcpu->kvm->mm != current->mm)
20332034
return -EIO;
20342035

2036+
if (unlikely(_IOC_TYPE(ioctl) != KVMIO))
2037+
return -EINVAL;
2038+
20352039
#if defined(CONFIG_S390) || defined(CONFIG_PPC) || defined(CONFIG_MIPS)
20362040
/*
20372041
* Special cases: vcpu ioctls that are asynchronous to vcpu execution,

0 commit comments

Comments
 (0)