Skip to content

Commit 4238737

Browse files
Alex Williamsonavikivity
authored andcommitted
KVM: Remove ability to assign a device without iommu support
This option has no users and it exposes a security hole that we can allow devices to be assigned without iommu protection. Make KVM_DEV_ASSIGN_ENABLE_IOMMU a mandatory option. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent 0924ab2 commit 4238737

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,9 @@ following flags are specified:
11511151
/* Depends on KVM_CAP_IOMMU */
11521152
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
11531153

1154+
The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
1155+
isolation of the device. Usages not specifying this flag are deprecated.
1156+
11541157
4.49 KVM_DEASSIGN_PCI_DEVICE
11551158

11561159
Capability: KVM_CAP_DEVICE_DEASSIGNMENT

‎virt/kvm/assigned-dev.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
487487
struct kvm_assigned_dev_kernel *match;
488488
struct pci_dev *dev;
489489

490+
if (!(assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU))
491+
return -EINVAL;
492+
490493
mutex_lock(&kvm->lock);
491494
idx = srcu_read_lock(&kvm->srcu);
492495

@@ -544,16 +547,14 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
544547

545548
list_add(&match->list, &kvm->arch.assigned_dev_head);
546549

547-
if (assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU) {
548-
if (!kvm->arch.iommu_domain) {
549-
r = kvm_iommu_map_guest(kvm);
550-
if (r)
551-
goto out_list_del;
552-
}
553-
r = kvm_assign_device(kvm, match);
550+
if (!kvm->arch.iommu_domain) {
551+
r = kvm_iommu_map_guest(kvm);
554552
if (r)
555553
goto out_list_del;
556554
}
555+
r = kvm_assign_device(kvm, match);
556+
if (r)
557+
goto out_list_del;
557558

558559
out:
559560
srcu_read_unlock(&kvm->srcu, idx);
@@ -593,8 +594,7 @@ static int kvm_vm_ioctl_deassign_device(struct kvm *kvm,
593594
goto out;
594595
}
595596

596-
if (match->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU)
597-
kvm_deassign_device(kvm, match);
597+
kvm_deassign_device(kvm, match);
598598

599599
kvm_free_assigned_device(kvm, match);
600600

0 commit comments

Comments
 (0)