RE: [PATCH] cdx: Fix driver_managed_dma check
From: Agarwal, Nikhil
Date: Mon May 05 2025 - 04:25:13 EST
> -----Original Message-----
> From: Robin Murphy <robin.murphy@xxxxxxx>
> Sent: Friday, April 25, 2025 7:09 PM
> To: joro@xxxxxxxxxx; will@xxxxxxxxxx; Gupta, Nipun <Nipun.Gupta@xxxxxxx>;
> Agarwal, Nikhil <nikhil.agarwal@xxxxxxx>
> Cc: iommu@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Will McVicker
> <willmcvicker@xxxxxxxxxx>
> Subject: [PATCH] cdx: Fix driver_managed_dma check
>
> Since it's not currently safe to take device_lock() in the IOMMU probe path, that can
> race against really_probe() setting dev->driver before attempting to bind. The race
> itself isn't so bad, since we're only concerned with dereferencing dev->driver itself
> anyway, but sadly my attempt to implement the check with minimal churn leads to a
> kind of TOCTOU issue, where dev->driver becomes valid after to_cdx_driver(NULL)
> is already computed, and thus the check fails to work as intended.
>
> Will and I both hit this with the platform bus, but the pattern here is the same, so fix
> it for correctness too.
>
> Reported-by: Will McVicker <willmcvicker@xxxxxxxxxx>
> Fixes: bcb81ac6ae3c ("iommu: Get DT/ACPI parsing into the proper probe path")
> Signed-off-by: Robin Murphy <robin.murphy@xxxxxxx>
Acked-by: Nikhil Agarwal <nikhil.agarwal@xxxxxxx>