The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc
@ 2026-05-09  2:43 Lu Baolu
  2026-05-09  2:43 ` [PATCH 1/3] iommu/vt-d: Disable DMAR for Intel Q35 IGFX Lu Baolu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Lu Baolu @ 2026-05-09  2:43 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Zhenzhong Duan, Naval Alcalá, iommu, linux-kernel

Hi Joerg,

The following fixes have been queued for v7.1-rc. They aim to fix the
following issues.

- Apply an existing quirk for Q35 graphic device.
- Skip dev_pasid teardown for the blocked domain to avoid out-of-bounds
  access.
- Return early if dev_pasid is missing to prevent NULL dereference or
  UAF.

These patches have been reviewed and tested and are ready for merge.
Please consider them for iommu/fix branch.

Best regards,
baolu

Naval Alcalá (1):
  iommu/vt-d: Disable DMAR for Intel Q35 IGFX

Zhenzhong Duan (2):
  iommu/vt-d: Fix oops due to out of scope access
  iommu/vt-d: Avoid NULL pointer dereference or refcount corruption

 drivers/iommu/intel/iommu.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

-- 
2.43.0


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

* [PATCH 1/3] iommu/vt-d: Disable DMAR for Intel Q35 IGFX
  2026-05-09  2:43 [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Lu Baolu
@ 2026-05-09  2:43 ` Lu Baolu
  2026-05-09  2:43 ` [PATCH 2/3] iommu/vt-d: Fix oops due to out of scope access Lu Baolu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2026-05-09  2:43 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Zhenzhong Duan, Naval Alcalá, iommu, linux-kernel

From: Naval Alcalá <ari@naval.cat>

Intel Q35 integrated graphics (8086:29b2) exhibits broken DMAR
behaviour similar to other G4x/GM45 devices for which DMAR is
already disabled via quirks.

When DMAR is enabled, the system may hard lock up during boot or
early device initialization, requiring a reset.

Add the missing PCI ID to the existing quirk list to disable
DMAR for this device.

Fixes: 1f76249cc3be ("iommu/vt-d: Declare Broadwell igfx dmar support snafu")
Cc: stable@vger.kernel.org
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=201185
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216064
Signed-off-by: Naval Alcalá <ari@naval.cat>
Link: https://lore.kernel.org/r/20260410161622.13549-1-ari@naval.cat
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index c3d18cd77d2f..2a6b6813a78d 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3937,6 +3937,9 @@ static void quirk_iommu_igfx(struct pci_dev *dev)
 	disable_igfx_iommu = 1;
 }
 
+/* Q35 integrated gfx dmar support is totally busted. */
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x29b2, quirk_iommu_igfx);
+
 /* G4x/GM45 integrated gfx dmar support is totally busted. */
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_igfx);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e00, quirk_iommu_igfx);
-- 
2.43.0


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

* [PATCH 2/3] iommu/vt-d: Fix oops due to out of scope access
  2026-05-09  2:43 [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Lu Baolu
  2026-05-09  2:43 ` [PATCH 1/3] iommu/vt-d: Disable DMAR for Intel Q35 IGFX Lu Baolu
@ 2026-05-09  2:43 ` Lu Baolu
  2026-05-09  2:43 ` [PATCH 3/3] iommu/vt-d: Avoid NULL pointer dereference or refcount corruption Lu Baolu
  2026-05-11  8:20 ` [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2026-05-09  2:43 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Zhenzhong Duan, Naval Alcalá, iommu, linux-kernel

From: Zhenzhong Duan <zhenzhong.duan@intel.com>

Below oops triggers when kill QEMU process:

  Oops: general protection fault, probably for non-canonical address 0x7fffffff844eaaa7: 0000 [#1] SMP NOPTI
  Call Trace:
   <TASK>
   do_raw_spin_lock+0xaa/0xc0
   _raw_spin_lock_irqsave+0x21/0x40
   domain_remove_dev_pasid+0x52/0x160
   intel_nested_set_dev_pasid+0x1b9/0x1e0
   __iommu_set_group_pasid+0x56/0x120
   pci_dev_reset_iommu_done+0xe3/0x180
   pcie_flr+0x65/0x160
   __pci_reset_function_locked+0x5b/0x120
   vfio_pci_core_close_device+0x63/0xe0 [vfio_pci_core]
   vfio_df_close+0x4f/0xa0
   vfio_df_unbind_iommufd+0x2d/0x60
   vfio_device_fops_release+0x3e/0x40
   __fput+0xe5/0x2c0
   task_work_run+0x58/0xa0
   do_exit+0x2c8/0x600
   do_group_exit+0x2f/0xa0
   get_signal+0x863/0x8c0
   arch_do_signal_or_restart+0x24/0x100
   exit_to_user_mode_loop+0x87/0x380
   do_syscall_64+0x2ff/0x11e0
   entry_SYSCALL_64_after_hwframe+0x76/0x7e

The global static blocked domain is a dummy domain without corresponding
dmar_domain structure, accessing beyond iommu_domain structure triggers
oops easily. Fix it by return early in domain_remove_dev_pasid() like
identity domain.

Fixes: 7d0c9da6c150 ("iommu/vt-d: Add set_dev_pasid callback for dma domain")
Cc: stable@vger.kernel.org
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20260421031347.1408890-1-zhenzhong.duan@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2a6b6813a78d..a4b123c33022 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3530,8 +3530,8 @@ void domain_remove_dev_pasid(struct iommu_domain *domain,
 	if (!domain)
 		return;
 
-	/* Identity domain has no meta data for pasid. */
-	if (domain->type == IOMMU_DOMAIN_IDENTITY)
+	/* Identity domain and blocked domain have no meta data for pasid. */
+	if (domain->type == IOMMU_DOMAIN_IDENTITY || domain->type == IOMMU_DOMAIN_BLOCKED)
 		return;
 
 	dmar_domain = to_dmar_domain(domain);
-- 
2.43.0


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

* [PATCH 3/3] iommu/vt-d: Avoid NULL pointer dereference or refcount corruption
  2026-05-09  2:43 [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Lu Baolu
  2026-05-09  2:43 ` [PATCH 1/3] iommu/vt-d: Disable DMAR for Intel Q35 IGFX Lu Baolu
  2026-05-09  2:43 ` [PATCH 2/3] iommu/vt-d: Fix oops due to out of scope access Lu Baolu
@ 2026-05-09  2:43 ` Lu Baolu
  2026-05-11  8:20 ` [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2026-05-09  2:43 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Zhenzhong Duan, Naval Alcalá, iommu, linux-kernel

From: Zhenzhong Duan <zhenzhong.duan@intel.com>

Commit 60f030f7418d ("iommu/vt-d: Avoid use of NULL after WARN_ON_ONCE")
fixed a NULL pointer dereference in an unlikely situation partly.

If dev_pasid is not found in the dev_pasids list, it remains NULL.
However, the teardown operations are executed unconditionally, this lead
to a NULL pointer dereference or refcount corruption.

If the domain was never attached to this IOMMU, info will be NULL, which
would cause an immediate dereference when checking --info->refcnt.

Even if info is not NULL, decrementing the refcount without having removed
a valid PASID might unbalance the count. This could lead to premature
dropping of the refcount to 0, potentially causing a use-after-free for the
remaining active devices sharing the domain.

Fix it by returning early if dev_pasid is NULL, before executing the
teardown operations.

Issue found by AI review and suggested by Kevin Tian.
https://sashiko.dev/#/patchset/20260421031347.1408890-1-zhenzhong.duan%40intel.com

Fixes: 60f030f7418d ("iommu/vt-d: Avoid use of NULL after WARN_ON_ONCE")
Cc: stable@vger.kernel.org
Suggested-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20260422033538.95000-1-zhenzhong.duan@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index a4b123c33022..4d0e65bc131d 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3545,12 +3545,13 @@ void domain_remove_dev_pasid(struct iommu_domain *domain,
 	}
 	spin_unlock_irqrestore(&dmar_domain->lock, flags);
 
+	if (WARN_ON_ONCE(!dev_pasid))
+		return;
+
 	cache_tag_unassign_domain(dmar_domain, dev, pasid);
 	domain_detach_iommu(dmar_domain, iommu);
-	if (!WARN_ON_ONCE(!dev_pasid)) {
-		intel_iommu_debugfs_remove_dev_pasid(dev_pasid);
-		kfree(dev_pasid);
-	}
+	intel_iommu_debugfs_remove_dev_pasid(dev_pasid);
+	kfree(dev_pasid);
 }
 
 static int blocking_domain_set_dev_pasid(struct iommu_domain *domain,
-- 
2.43.0


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

* Re: [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc
  2026-05-09  2:43 [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Lu Baolu
                   ` (2 preceding siblings ...)
  2026-05-09  2:43 ` [PATCH 3/3] iommu/vt-d: Avoid NULL pointer dereference or refcount corruption Lu Baolu
@ 2026-05-11  8:20 ` Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2026-05-11  8:20 UTC (permalink / raw)
  To: Lu Baolu; +Cc: Zhenzhong Duan, Naval Alcalá, iommu, linux-kernel

On Sat, May 09, 2026 at 10:43:43AM +0800, Lu Baolu wrote:
> Naval Alcalá (1):
>   iommu/vt-d: Disable DMAR for Intel Q35 IGFX
> 
> Zhenzhong Duan (2):
>   iommu/vt-d: Fix oops due to out of scope access
>   iommu/vt-d: Avoid NULL pointer dereference or refcount corruption
> 
>  drivers/iommu/intel/iommu.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Applied, thanks Baolu.

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

end of thread, other threads:[~2026-05-11  8:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09  2:43 [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Lu Baolu
2026-05-09  2:43 ` [PATCH 1/3] iommu/vt-d: Disable DMAR for Intel Q35 IGFX Lu Baolu
2026-05-09  2:43 ` [PATCH 2/3] iommu/vt-d: Fix oops due to out of scope access Lu Baolu
2026-05-09  2:43 ` [PATCH 3/3] iommu/vt-d: Avoid NULL pointer dereference or refcount corruption Lu Baolu
2026-05-11  8:20 ` [PATCH 0/3] [PULL REQUEST] iommu/vt-d: Fixes for v7.1-rc Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox