The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 1/1] iommu/vt-d: Avoid relying on pci_ats_supported() for rbtree removal
@ 2026-11-23  0:38 Lu Baolu
  2026-11-23 17:22 ` Bjorn Helgaas
  2026-11-23 20:14 ` Pranjal Shrivastava
  0 siblings, 2 replies; 3+ messages in thread
From: Lu Baolu @ 2026-11-23  0:38 UTC (permalink / raw)
  To: iommu; +Cc: Kevin Tian, Bjorn Helgaas, linux-kernel, Lu Baolu

Commit 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in iommu probe path") made
the device rbtree insertion in intel_iommu_probe_device() conditional on
pci_ats_supported(). To match, intel_iommu_release_device() only removes
the device from the rbtree if pci_ats_supported() is still true.

That relies on pci_ats_supported() returning the same result at release
as it did at probe. If it changes in between, the rbtree can retain an
entry after its device_domain_info has been freed, resulting in a
use-after-free during a later lookup.

Checking RB_EMPTY_NODE() to track rbtree membership is common in the
iommu subsystem. Since device_rbtree_remove() safely handles an empty
node, call it unconditionally in the release path. This makes removal
depend on the device's actual rbtree membership.

Fixes: 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in iommu probe path")
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 5a2e705a2f2e..82f7bd8ecadf 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3393,6 +3393,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
 
 	info->dev = dev;
 	info->iommu = iommu;
+	/* An empty node marks the device as not in the rbtree. */
 	RB_CLEAR_NODE(&info->node);
 	if (dev_is_pci(dev)) {
 		if (ecap_dev_iotlb_support(iommu->ecap) &&
@@ -3508,8 +3509,7 @@ static void intel_iommu_release_device(struct device *dev)
 	}
 
 	mutex_lock(&iommu->iopf_lock);
-	if (dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)))
-		device_rbtree_remove(info);
+	device_rbtree_remove(info);
 	mutex_unlock(&iommu->iopf_lock);
 
 	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev) &&
-- 
2.43.0


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

* Re: [PATCH 1/1] iommu/vt-d: Avoid relying on pci_ats_supported() for rbtree removal
  2026-11-23  0:38 [PATCH 1/1] iommu/vt-d: Avoid relying on pci_ats_supported() for rbtree removal Lu Baolu
@ 2026-11-23 17:22 ` Bjorn Helgaas
  2026-11-23 20:14 ` Pranjal Shrivastava
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2026-11-23 17:22 UTC (permalink / raw)
  To: Lu Baolu
  Cc: iommu, Kevin Tian, Bjorn Helgaas, linux-kernel, Danny Gonzalez,
	David Decotigny, Sheena Mohan, Pranjal Shrivastava

[+cc Danny, David, Sheena, Pranjal]

On Mon, Nov 23, 2026 at 08:38:05AM +0800, Lu Baolu wrote:
> Commit 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in iommu probe path") made
> the device rbtree insertion in intel_iommu_probe_device() conditional on
> pci_ats_supported(). To match, intel_iommu_release_device() only removes
> the device from the rbtree if pci_ats_supported() is still true.
> 
> That relies on pci_ats_supported() returning the same result at release
> as it did at probe. If it changes in between, the rbtree can retain an
> entry after its device_domain_info has been freed, resulting in a
> use-after-free during a later lookup.
> 
> Checking RB_EMPTY_NODE() to track rbtree membership is common in the
> iommu subsystem. Since device_rbtree_remove() safely handles an empty
> node, call it unconditionally in the release path. This makes removal
> depend on the device's actual rbtree membership.
> 
> Fixes: 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in iommu probe path")
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>

Looks good to me, thanks!

> ---
>  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 5a2e705a2f2e..82f7bd8ecadf 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -3393,6 +3393,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
>  
>  	info->dev = dev;
>  	info->iommu = iommu;
> +	/* An empty node marks the device as not in the rbtree. */
>  	RB_CLEAR_NODE(&info->node);
>  	if (dev_is_pci(dev)) {
>  		if (ecap_dev_iotlb_support(iommu->ecap) &&
> @@ -3508,8 +3509,7 @@ static void intel_iommu_release_device(struct device *dev)
>  	}
>  
>  	mutex_lock(&iommu->iopf_lock);
> -	if (dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)))
> -		device_rbtree_remove(info);
> +	device_rbtree_remove(info);
>  	mutex_unlock(&iommu->iopf_lock);
>  
>  	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev) &&
> -- 
> 2.43.0
> 

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

* Re: [PATCH 1/1] iommu/vt-d: Avoid relying on pci_ats_supported() for rbtree removal
  2026-11-23  0:38 [PATCH 1/1] iommu/vt-d: Avoid relying on pci_ats_supported() for rbtree removal Lu Baolu
  2026-11-23 17:22 ` Bjorn Helgaas
@ 2026-11-23 20:14 ` Pranjal Shrivastava
  1 sibling, 0 replies; 3+ messages in thread
From: Pranjal Shrivastava @ 2026-11-23 20:14 UTC (permalink / raw)
  To: Lu Baolu; +Cc: iommu, Kevin Tian, Bjorn Helgaas, linux-kernel

On Mon, Nov 23, 2026 at 08:38:05AM +0800, Lu Baolu wrote:
> Commit 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in iommu probe path") made
> the device rbtree insertion in intel_iommu_probe_device() conditional on
> pci_ats_supported(). To match, intel_iommu_release_device() only removes
> the device from the rbtree if pci_ats_supported() is still true.
> 
> That relies on pci_ats_supported() returning the same result at release
> as it did at probe. If it changes in between, the rbtree can retain an
> entry after its device_domain_info has been freed, resulting in a
> use-after-free during a later lookup.
> 

FWIW, this already happens today for devices whose ATS is disabled by a
quirk and that are added after the IOMMU notifiers are set up (hot-plug,
VFs): the FINAL fixups clear ats_cap after the IOMMU probe. David's
patch [1] fixes that on the PCI side by moving those quirks to header
fixups, and this patch makes the vt-d side robust regardless, which also
covers Danny's change.

So maybe this (and David's patch) deserve a cc: stable?

> Checking RB_EMPTY_NODE() to track rbtree membership is common in the
> iommu subsystem. Since device_rbtree_remove() safely handles an empty
> node, call it unconditionally in the release path. This makes removal
> depend on the device's actual rbtree membership.
> 
> Fixes: 89436f4f5412 ("iommu/vt-d: Fix WARN_ON in iommu probe path")
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

[1] https://lore.kernel.org/all/20261110003353.1824793-1-dmatlack@google.com/

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  0:38 [PATCH 1/1] iommu/vt-d: Avoid relying on pci_ats_supported() for rbtree removal Lu Baolu
2026-11-23 17:22 ` Bjorn Helgaas
2026-11-23 20:14 ` Pranjal Shrivastava

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