Skip to contentSkip to conversation

iommu/vt-d: Several fixes for 5.1

PATCH Applied Lu Baolu 3 participants 7 messages Mar 1, 2019 – Mar 2, 2019 IOMMU

lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

cover iommu/vt-d: Several fixes for 5.1

Hi Joerg,

This includes several small fixes. All are stable kernel irrelated. Please consider it for 5.1-rc1.

Best regards,
Lu Baolu

Lu Baolu (4):
iommu/vt-d: Disable ATS support on untrusted devices iommu/vt-d: Set context field after value initialized iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() iommu/vt-d: Get domain ID before clear pasid entry

 drivers/iommu/intel-iommu.c | 6 ++++--
 drivers/iommu/intel-pasid.c | 2 +-
 drivers/iommu/intel-svm.c   | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/4 iommu/vt-d: Disable ATS support on untrusted devices

Commit fb58fdcd295b9 ("iommu/vt-d: Do not enable ATS for untrusted devices") disables ATS support on the devices which have been marked as untrusted. Unfortunately this is not enough to fix the DMA attack vulnerabiltiies because IOMMU driver allows translated requests as long as a device advertises the ATS capability. Hence a malicious peripheral device could use this to bypass IOMMU.

This disables the ATS support on untrusted devices by clearing the internal per-device ATS mark. As the result, IOMMU driver will block any translated requests from any device marked as untrusted.

Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>
Fixes fb58fdcd295b9 ("iommu/vt-d: Do not enable ATS for untrusted devices")
---
 drivers/iommu/intel-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +2 -1
index f8f6d46c60f4..abdd165a829c 100644
@@ -2484,7 +2484,8 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
 	if (dev && dev_is_pci(dev)) {
 		struct pci_dev *pdev = to_pci_dev(info->dev);
 
-		if (!pci_ats_disabled() &&
+		if (!pdev->untrusted &&
+		    !pci_ats_disabled() &&
 		    ecap_dev_iotlb_support(iommu->ecap) &&
 		    pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS) &&
 		    dmar_find_matched_atsr_unit(pdev))
Signature · 1 line
2.17.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices

Quoted 7 lines · Lu Baolu

Commit fb58fdcd295b9 ("iommu/vt-d: Do not enable ATS for untrusted devices") disables ATS support on the devices which have been marked as untrusted. Unfortunately this is not enough to fix the DMA attack vulnerabiltiies because IOMMU driver allows translated requests as long as a device advertises the ATS capability. Hence a malicious peripheral device could use this to bypass IOMMU.

Quoted 6 lines

This disables the ATS support on untrusted devices by clearing the internal per-device ATS mark. As the result, IOMMU driver will block any translated requests from any device marked as untrusted.

Cc Jacob Pan <[email protected]>
Cc Mika Westerberg <[email protected]>
author
#3 lore raw

PATCH 2/4 iommu/vt-d: Set context field after value initialized

In reply to Lu Baolu

Otherwise, the translation type field of a context entry for a PCI device will always be 0. All translated DMA requests will be blocked by IOMMU. As the result, the PCI devices with PCI ATS (device IOTBL) support won't work as expected.

Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Fixes 7373a8cc38197 ("iommu/vt-d: Setup context and enable RID2PASID support")
---
 drivers/iommu/intel-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +2 -1
index abdd165a829c..c968b3c7bae0 100644
@@ -2056,7 +2056,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
 		int agaw;
 
 		context_set_domain_id(context, did);
-		context_set_translation_type(context, translation);
 
 		if (translation != CONTEXT_TT_PASS_THROUGH) {
 			/*
@@ -2086,6 +2085,8 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
 			 */
 			context_set_address_width(context, iommu->msagaw);
 		}
+
+		context_set_translation_type(context, translation);
 	}
 
 	context_set_fault_enable(context);
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 3/4 iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm()

In reply to Lu Baolu

Intel IOMMU could be turned off with intel_iommu=off. If Intel IOMMU is off, the intel_iommu struct will not be initialized. When device drivers call intel_svm_bind_mm(), the NULL pointer reference will happen there.

Add dmar_disabled check to avoid NULL pointer reference.

Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Fixes 2f26e0a9c9860 ("iommu/vt-d: Add basic SVM PASID support")
---
 drivers/iommu/intel-svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel-svm.c +1 -1
index c79540deaf00..3a4b09ae8561 100644
@@ -234,7 +234,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
 	int pasid_max;
 	int ret;
 
-	if (!iommu)
+	if (!iommu || dmar_disabled)
 		return -EINVAL;
 
 	if (dev_is_pci(dev)) {
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH 4/4 iommu/vt-d: Get domain ID before clear pasid entry

In reply to Lu Baolu

After tearing down a pasid entry, the domain id is used to invalidate the translation caches. Retrieve the domain id from the pasid entry value before clearing the pasid entry. Otherwise, we will always use domain id 0.

Cc Ashok Raj <[email protected]>
Cc Jacob Pan <[email protected]>
Fixes 6f7db75e1c469 ("iommu/vt-d: Add second level page table interface")
---
 drivers/iommu/intel-pasid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel-pasid.c +1 -1
index 53fe5248d8f1..03b12d2ee213 100644
@@ -466,8 +466,8 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu,
 	if (WARN_ON(!pte))
 		return;
 
-	intel_pasid_clear_entry(dev, pasid);
 	did = pasid_get_domain_id(pte);
+	intel_pasid_clear_entry(dev, pasid);
 
 	if (!ecap_coherent(iommu->ecap))
 		clflush_cache_range(pte, sizeof(*pte));
Signature · 1 line
2.17.1
maintainer Applied
#6 lore raw
In reply to Lu Baolu
Quoted 5 lines · Lu Baolu

Hi Joerg,

This includes several small fixes. All are stable kernel irrelated. Please consider it for 5.1-rc1.

Quoted 8 lines

Best regards,
Lu Baolu

Lu Baolu (4):
iommu/vt-d: Disable ATS support on untrusted devices iommu/vt-d: Set context field after value initialized iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() iommu/vt-d: Get domain ID before clear pasid entry

Applied, thanks.