iommu/vt-d: Fixes for v7.1-rc
Subsystems (2)
Lu Baolu
maintainerHi 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(-)
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 1/3 iommu/vt-d: Disable DMAR for Intel Q35 IGFX
From: Naval Alcalá <[email protected]>
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.
--- drivers/iommu/intel/iommu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iommu/intel/iommu.c +3 -0
@@ -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);
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 2/3 iommu/vt-d: Fix oops due to out of scope access
In reply to Lu BaoluFrom: Zhenzhong Duan <[email protected]>
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.
--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +2 -2
@@ -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);
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 3/3 iommu/vt-d: Avoid NULL pointer dereference or refcount corruption
In reply to Lu BaoluFrom: Zhenzhong Duan <[email protected]>
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
--- drivers/iommu/intel/iommu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/iommu/intel/iommu.c +5 -4
@@ -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,
Signature · 1 line
2.43.0
Quoted 9 lines · Lu Baolu
Naval Alcalá (1):
iommu/vt-d: Disable DMAR for Intel Q35 IGFXZhenzhong Duan (2):
iommu/vt-d: Fix oops due to out of scope access iommu/vt-d: Avoid NULL pointer dereference or refcount corruptiondrivers/iommu/intel/iommu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
Applied, thanks Baolu.