public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Forbid /dev/kvm being opened by a compat task when CONFIG_KVM_COMPAT=n
@ 2019-11-13 16:05 Marc Zyngier
  2019-11-13 16:12 ` Paolo Bonzini
  2019-11-13 18:43 ` Christian Borntraeger
  0 siblings, 2 replies; 11+ messages in thread
From: Marc Zyngier @ 2019-11-13 16:05 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář, James Morse,
	Julien Thierry, Suzuki K Poulose, James Hogan, Paul Mackerras,
	Christian Borntraeger, Janosch Frank, David Hildenbrand,
	Cornelia Huck, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel, Peter Maydell

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>
---
 virt/kvm/kvm_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 543024c7a87f..1243e48dc717 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -122,7 +122,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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-11-15  9:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-13 16:05 [PATCH] KVM: Forbid /dev/kvm being opened by a compat task when CONFIG_KVM_COMPAT=n Marc Zyngier
2019-11-13 16:12 ` Paolo Bonzini
2019-11-13 18:43 ` Christian Borntraeger
2019-11-13 21:23   ` Peter Maydell
2019-11-14  8:15     ` Marc Zyngier
2019-11-14  8:20       ` Christian Borntraeger
2019-11-14 12:12         ` Paolo Bonzini
2019-11-14 13:22           ` Marc Zyngier
2019-11-14 13:28             ` Peter Maydell
2019-11-15  9:53               ` Paolo Bonzini
2019-11-15  9:14             ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox