]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.1.10/kvm-remove-ability-to-assign-a-device-without-iommu-support.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.1.10 / kvm-remove-ability-to-assign-a-device-without-iommu-support.patch
CommitLineData
faa88b27
GKH
1From avi@redhat.com Thu Jan 12 14:57:35 2012
2From: Avi Kivity <avi@redhat.com>
3Date: Thu, 12 Jan 2012 12:39:53 +0200
4Subject: KVM: Remove ability to assign a device without iommu support
5To: stable@vger.kernel.org
6Cc: kvm@vger.kernel.org, Marcelo Tosatti <mtosatti@redhat.com>
7Message-ID: <1326364794-18150-4-git-send-email-avi@redhat.com>
8
9
10From: Alex Williamson <alex.williamson@redhat.com>
11
12(cherry picked from commit 423873736b78f549fbfa2f715f2e4de7e6c5e1e9)
13
14This option has no users and it exposes a security hole that we
15can allow devices to be assigned without iommu protection. Make
16KVM_DEV_ASSIGN_ENABLE_IOMMU a mandatory option.
17
18Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
19Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
20Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
21---
22 Documentation/virtual/kvm/api.txt | 3 +++
23 virt/kvm/assigned-dev.c | 18 +++++++++---------
24 2 files changed, 12 insertions(+), 9 deletions(-)
25
26--- a/Documentation/virtual/kvm/api.txt
27+++ b/Documentation/virtual/kvm/api.txt
28@@ -1131,6 +1131,9 @@ following flags are specified:
29 /* Depends on KVM_CAP_IOMMU */
30 #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
31
32+The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
33+isolation of the device. Usages not specifying this flag are deprecated.
34+
35 4.49 KVM_DEASSIGN_PCI_DEVICE
36
37 Capability: KVM_CAP_DEVICE_DEASSIGNMENT
38--- a/virt/kvm/assigned-dev.c
39+++ b/virt/kvm/assigned-dev.c
40@@ -481,6 +481,9 @@ static int kvm_vm_ioctl_assign_device(st
41 struct kvm_assigned_dev_kernel *match;
42 struct pci_dev *dev;
43
44+ if (!(assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU))
45+ return -EINVAL;
46+
47 mutex_lock(&kvm->lock);
48 idx = srcu_read_lock(&kvm->srcu);
49
50@@ -538,16 +541,14 @@ static int kvm_vm_ioctl_assign_device(st
51
52 list_add(&match->list, &kvm->arch.assigned_dev_head);
53
54- if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) {
55- if (!kvm->arch.iommu_domain) {
56- r = kvm_iommu_map_guest(kvm);
57- if (r)
58- goto out_list_del;
59- }
60- r = kvm_assign_device(kvm, match);
61+ if (!kvm->arch.iommu_domain) {
62+ r = kvm_iommu_map_guest(kvm);
63 if (r)
64 goto out_list_del;
65 }
66+ r = kvm_assign_device(kvm, match);
67+ if (r)
68+ goto out_list_del;
69
70 out:
71 srcu_read_unlock(&kvm->srcu, idx);
72@@ -587,8 +588,7 @@ static int kvm_vm_ioctl_deassign_device(
73 goto out;
74 }
75
76- if (match->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU)
77- kvm_deassign_device(kvm, match);
78+ kvm_deassign_device(kvm, match);
79
80 kvm_free_assigned_device(kvm, match);
81