iommu/vt-d: Several fixes for 5.1
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
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.
--- drivers/iommu/intel-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +2 -1
@@ -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
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]>
PATCH 2/4 iommu/vt-d: Set context field after value initialized
In reply to Lu BaoluOtherwise, 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.
--- drivers/iommu/intel-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +2 -1
@@ -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
PATCH 3/4 iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm()
In reply to Lu BaoluIntel 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.
--- drivers/iommu/intel-svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel-svm.c +1 -1
@@ -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
PATCH 4/4 iommu/vt-d: Get domain ID before clear pasid entry
In reply to Lu BaoluAfter 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.
--- drivers/iommu/intel-pasid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel-pasid.c +1 -1
@@ -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
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 BaoluLu 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 inintel_svm_bind_mm()iommu/vt-d: Get domain ID before clear pasid entry
Applied, thanks.