Skip to contentSkip to conversation

iommu/vt-d: Don't apply gfx quirks to untrusted devices

PATCH Superseded Rajat Jain 2 participants 2 messages Jun 2, 2020 IOMMU

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Rajat Jain

author
#0 lore raw

PATCH v2 1/1 iommu/vt-d: Don't apply gfx quirks to untrusted devices

Currently, an external malicious PCI device can masquerade the VID:PID of faulty gfx devices, and thus apply iommu quirks to effectively disable the IOMMU restrictions for itself.

Thus we need to ensure that the device we are applying quirks to, is indeed an internal trusted device.

---
V2: - Change the warning print strings.
- Add Lu Baolu's acknowledgement.

 drivers/iommu/intel-iommu.c | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/iommu/intel-iommu.c +38 -0
index ef0a5246700e5..fdfbea4ff8cb3 100644
@@ -6214,6 +6214,13 @@ const struct iommu_ops intel_iommu_ops = {
 
 static void quirk_iommu_igfx(struct pci_dev *dev)
 {
+	if (dev->untrusted) {
+		pci_warn(dev,
+			 "Skipping IOMMU quirk %s() for potentially untrusted device\n",
+			 __func__);
+		return;
+	}
+
 	pci_info(dev, "Disabling IOMMU for graphics on this chipset\n");
 	dmar_map_gfx = 0;
 }
@@ -6255,6 +6262,13 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x163D, quirk_iommu_igfx);
 
 static void quirk_iommu_rwbf(struct pci_dev *dev)
 {
+	if (dev->untrusted) {
+		pci_warn(dev,
+			 "Skipping IOMMU quirk %s() for potentially untrusted device\n",
+			 __func__);
+		return;
+	}
+
 	/*
 	 * Mobile 4 Series Chipset neglects to set RWBF capability,
 	 * but needs it. Same seems to hold for the desktop versions.
@@ -6285,6 +6299,13 @@ static void quirk_calpella_no_shadow_gtt(struct pci_dev *dev)
 {
 	unsigned short ggc;
 
+	if (dev->untrusted) {
+		pci_warn(dev,
+			 "Skipping IOMMU quirk %s() for potentially untrusted device\n",
+			 __func__);
+		return;
+	}
+
 	if (pci_read_config_word(dev, GGC, &ggc))
 		return;
 
@@ -6318,6 +6339,15 @@ static void __init check_tylersburg_isoch(void)
 	pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x3a3e, NULL);
 	if (!pdev)
 		return;
+
+	if (pdev->untrusted) {
+		pci_warn(pdev,
+			 "Skipping IOMMU quirk %s() for potentially untrusted device\n",
+			 __func__);
+		pci_dev_put(pdev);
+		return;
+	}
+
 	pci_dev_put(pdev);
 
 	/* System Management Registers. Might be hidden, in which case
@@ -6327,6 +6357,14 @@ static void __init check_tylersburg_isoch(void)
 	if (!pdev)
 		return;
 
+	if (pdev->untrusted) {
+		pci_warn(pdev,
+			 "Skipping IOMMU quirk %s() for potentially untrusted device\n",
+			 __func__);
+		pci_dev_put(pdev);
+		return;
+	}
+
 	if (pci_read_config_dword(pdev, 0x188, &vtisochctrl)) {
 		pci_dev_put(pdev);
 		return;
Signature · 1 line
2.27.0.rc2.251.g90737beb825-goog
#1 lore raw

Hi Rajat

Quoted 21 lines · Rajat Jain

Currently, an external malicious PCI device can masquerade the VID:PID of faulty gfx devices, and thus apply iommu quirks to effectively disable the IOMMU restrictions for itself.

Thus we need to ensure that the device we are applying quirks to, is indeed an internal trusted device.

---
V2: - Change the warning print strings.
- Add Lu Baolu's acknowledgement.

 drivers/iommu/intel-iommu.c | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/iommu/intel-iommu.c +0 -0
index ef0a5246700e5..fdfbea4ff8cb3 100644

drivers/iommu/intel-iommu.c const struct iommu_ops intel_iommu_ops = { · line 6223

Quoted 10 lines
drivers/iommu/intel-iommu.c +7 -0
@@ -6214,6 +6214,13 @@ const struct iommu_ops intel_iommu_ops = {
 
 static void quirk_iommu_igfx(struct pci_dev *dev)
 {
+	if (dev->untrusted) {
+		pci_warn(dev,
+			 "Skipping IOMMU quirk %s() for potentially untrusted device\n",
+			 __func__);
+		return;
+	}
+

This check and code seems to be happening several times. Maybe add a simple function to do the test and use in all places?

Cheers,
Ashok