Re: [PATCH] driver core: enforce device_lock for driver_match_device()
From: Danilo Krummrich
Date: Tue Jun 02 2026 - 12:51:31 EST
On Tue Jun 2, 2026 at 6:08 PM CEST, Runyu Xiao wrote:
> This issue was first flagged by our static analysis tool while auditing
> driver_override match paths, then manually confirmed on Linux v6.18.21.
> We reproduced the race with no-device KCSAN/MSV harnesses across AMBA,
> WMI, RPMSG, VMBUS, VDPA, CDX, CSS, FSL-MC, and PCI. Those reports all
> reduce to the same core-side gap in driver_match_device().
This is all fixed in driver-core-next already, please also see [1] and [2].
> Fix this by introducing driver_match_device_locked(), which guarantees
> holding device_lock(dev) with a scoped guard before entering the bus
> match callback. Convert the two unlocked call sites to this helper, and
> add a device_lock_assert() to driver_match_device() so the contract is
> explicit.
This approach was reverted [3] for the reasons documented in the linked patch.
Thanks,
Danilo
[1] https://lore.kernel.org/driver-core/20260303115720.48783-1-dakr@xxxxxxxxxx/
[2] https://lore.kernel.org/driver-core/20260324005919.2408620-1-dakr@xxxxxxxxxx/
[3] https://lore.kernel.org/driver-core/20260302002545.19389-1-dakr@xxxxxxxxxx/