All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] iommu/vt-d: Several fixes for 5.1
@ 2019-03-01  3:23 Lu Baolu
  2019-03-01  3:23 ` [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices Lu Baolu
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Lu Baolu @ 2019-03-01  3:23 UTC (permalink / raw)
  To: Joerg Roedel, David Woodhouse
  Cc: ashok.raj, jacob.jun.pan, kevin.tian, yi.l.liu, iommu,
	linux-kernel, Lu Baolu

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(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices
  2019-03-01  3:23 [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Lu Baolu
@ 2019-03-01  3:23 ` Lu Baolu
  2019-03-02  8:29   ` Mika Westerberg
  2019-03-01  3:23 ` [PATCH 2/4] iommu/vt-d: Set context field after value initialized Lu Baolu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Lu Baolu @ 2019-03-01  3:23 UTC (permalink / raw)
  To: Joerg Roedel, David Woodhouse
  Cc: ashok.raj, jacob.jun.pan, kevin.tian, yi.l.liu, iommu,
	linux-kernel, Lu Baolu, Jacob Pan, Mika Westerberg

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 <jacob.jun.pan@linux.intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Suggested-by: Kevin Tian <kevin.tian@intel.com>
Suggested-by: Ashok Raj <ashok.raj@intel.com>
Fixes: fb58fdcd295b9 ("iommu/vt-d: Do not enable ATS for untrusted devices")
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index f8f6d46c60f4..abdd165a829c 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -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))
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] iommu/vt-d: Set context field after value initialized
  2019-03-01  3:23 [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Lu Baolu
  2019-03-01  3:23 ` [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices Lu Baolu
@ 2019-03-01  3:23 ` Lu Baolu
  2019-03-01  3:23 ` [PATCH 3/4] iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() Lu Baolu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2019-03-01  3:23 UTC (permalink / raw)
  To: Joerg Roedel, David Woodhouse
  Cc: ashok.raj, jacob.jun.pan, kevin.tian, yi.l.liu, iommu,
	linux-kernel, Lu Baolu, Jacob Pan

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 <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Suggested-by: Kevin Tian <kevin.tian@intel.com>
Fixes: 7373a8cc38197 ("iommu/vt-d: Setup context and enable RID2PASID support")
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index abdd165a829c..c968b3c7bae0 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm()
  2019-03-01  3:23 [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Lu Baolu
  2019-03-01  3:23 ` [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices Lu Baolu
  2019-03-01  3:23 ` [PATCH 2/4] iommu/vt-d: Set context field after value initialized Lu Baolu
@ 2019-03-01  3:23 ` Lu Baolu
  2019-03-01  3:23 ` [PATCH 4/4] iommu/vt-d: Get domain ID before clear pasid entry Lu Baolu
  2019-03-01  9:24 ` [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Joerg Roedel
  4 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2019-03-01  3:23 UTC (permalink / raw)
  To: Joerg Roedel, David Woodhouse
  Cc: ashok.raj, jacob.jun.pan, kevin.tian, yi.l.liu, iommu,
	linux-kernel, Lu Baolu, Jacob Pan

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 <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Reported-by: Dave Jiang <dave.jiang@intel.com>
Fixes: 2f26e0a9c9860 ("iommu/vt-d: Add basic SVM PASID support")
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c
index c79540deaf00..3a4b09ae8561 100644
--- a/drivers/iommu/intel-svm.c
+++ b/drivers/iommu/intel-svm.c
@@ -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)) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] iommu/vt-d: Get domain ID before clear pasid entry
  2019-03-01  3:23 [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Lu Baolu
                   ` (2 preceding siblings ...)
  2019-03-01  3:23 ` [PATCH 3/4] iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() Lu Baolu
@ 2019-03-01  3:23 ` Lu Baolu
  2019-03-01  9:24 ` [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Joerg Roedel
  4 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2019-03-01  3:23 UTC (permalink / raw)
  To: Joerg Roedel, David Woodhouse
  Cc: ashok.raj, jacob.jun.pan, kevin.tian, yi.l.liu, iommu,
	linux-kernel, Lu Baolu, Jacob Pan

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 <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
Fixes: 6f7db75e1c469 ("iommu/vt-d: Add second level page table interface")
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel-pasid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c
index 53fe5248d8f1..03b12d2ee213 100644
--- a/drivers/iommu/intel-pasid.c
+++ b/drivers/iommu/intel-pasid.c
@@ -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));
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] iommu/vt-d: Several fixes for 5.1
  2019-03-01  3:23 [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Lu Baolu
                   ` (3 preceding siblings ...)
  2019-03-01  3:23 ` [PATCH 4/4] iommu/vt-d: Get domain ID before clear pasid entry Lu Baolu
@ 2019-03-01  9:24 ` Joerg Roedel
  4 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2019-03-01  9:24 UTC (permalink / raw)
  To: Lu Baolu
  Cc: David Woodhouse, ashok.raj, jacob.jun.pan, kevin.tian, yi.l.liu,
	iommu, linux-kernel

On Fri, Mar 01, 2019 at 11:23:09AM +0800, Lu Baolu wrote:
> 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

Applied, thanks.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices
  2019-03-01  3:23 ` [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices Lu Baolu
@ 2019-03-02  8:29   ` Mika Westerberg
  0 siblings, 0 replies; 7+ messages in thread
From: Mika Westerberg @ 2019-03-02  8:29 UTC (permalink / raw)
  To: Lu Baolu
  Cc: Joerg Roedel, David Woodhouse, ashok.raj, jacob.jun.pan,
	kevin.tian, yi.l.liu, iommu, linux-kernel, Jacob Pan

On Fri, Mar 01, 2019 at 11:23:10AM +0800, Lu Baolu wrote:
> 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 <jacob.jun.pan@linux.intel.com>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-02  8:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01  3:23 [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Lu Baolu
2019-03-01  3:23 ` [PATCH 1/4] iommu/vt-d: Disable ATS support on untrusted devices Lu Baolu
2019-03-02  8:29   ` Mika Westerberg
2019-03-01  3:23 ` [PATCH 2/4] iommu/vt-d: Set context field after value initialized Lu Baolu
2019-03-01  3:23 ` [PATCH 3/4] iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() Lu Baolu
2019-03-01  3:23 ` [PATCH 4/4] iommu/vt-d: Get domain ID before clear pasid entry Lu Baolu
2019-03-01  9:24 ` [PATCH 0/4] iommu/vt-d: Several fixes for 5.1 Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.