Re: [PATCH v2 1/3] driver core: fix parent lock use-after-free on USB disconnect

From: Alan Stern

Date: Wed Oct 14 2026 - 11:30:57 EST


On Wed, Oct 14, 2026 at 04:49:31PM +0200, Danilo Krummrich wrote:
> On Wed Oct 14, 2026 at 3:31 PM CEST, Johan Hovold wrote:
> > + * @need_parent_lock: When probing or removing a device of this type,
> > + * driver core should lock the device's parent. Note that
> > + * the device must hold a reference to its parent.
>
> For the reasons described in [1], I object to making subsystems responsible for
> the parent reference needed by driver core's delayed accesses. The driver core
> should acquire and release that reference internally.
>
> [1] https://lore.kernel.org/driver-core/DM4N25JXKTQM.3K7TP9HM68KQ2@xxxxxxxxxx/
When is the appropriate time to take the reference? Since it is going
to be dropped when the child device is released, the logical time to
take it is when the child device is initialized. But at that time, the
caller may not have set the bus_type or device_type.

Taking the reference when the child is added would work. But then how
would the release routine know whether or not to drop the reference?
Add an extra flag bit to keep track of this?

Alan Stern