All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: avoid klist_remove() on unattached knode_driver
@ 2026-08-20  5:55 Nguyen Quang Le Kien
  2026-08-20  6:05 ` [PATCH v2] " Nguyen Quang Le Kien
  0 siblings, 1 reply; 16+ messages in thread
From: Nguyen Quang Le Kien @ 2026-08-20  5:55 UTC (permalink / raw)
  To: gregkh, rafael, dakr
  Cc: driver-core, linux-usb, linux-kernel, Nguyen Quang Le Kien,
	syzbot+87188222c77c0dbbdb4d

usb_driver_claim_interface() sets dev->driver directly and skips
device_bind_driver() when the interface is not yet registered, so the
device can reach teardown with dev->driver set but knode_driver never
added to the driver's klist_devices. __device_release_driver() then
unconditionally calls klist_remove() on the unattached node, which
dereferences a NULL klist pointer in klist_put() and crashes.

Guard the klist_remove() with klist_node_attached(), mirroring the
existing check in bus_remove_device() for knode_bus.

Reported-by: syzbot+87188222c77c0dbbdb4d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=87188222c77c0dbbdb4d
Signed-off-by: Nguyen Quang Le Kien <khiemtranzo532001@gmail.com>
---
 drivers/base/dd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 60c005223..14752a5e5 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1354,7 +1354,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 		device_unbind_cleanup(dev);
 		device_links_driver_cleanup(dev);
 
-		klist_remove(&dev->p->knode_driver);
+		if (klist_node_attached(&dev->p->knode_driver))
+			klist_remove(&dev->p->knode_driver);
 		device_pm_check_callbacks(dev);
 
 		bus_notify(dev, BUS_NOTIFY_UNBOUND_DRIVER);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread
* Re: [PATCH v4] driver core: avoid klist_remove() on unattached knode_driver
@ 2026-08-24  4:41 Nguyen Quang Le Kien
  0 siblings, 0 replies; 16+ messages in thread
From: Nguyen Quang Le Kien @ 2026-08-24  4:41 UTC (permalink / raw)
  To: linux-usb
  Cc: Nguyen Quang Le Kien, Danilo Krummrich, Alan Stern, Greg KH,
	Rafael J . Wysocki, driver-core, linux-kernel,
	syzbot+87188222c77c0dbbdb4d, stable

In-Reply-To: <DKU2J83B6IX6.2CG1WOB66WC39@kernel.org>
References: <DKU2J83B6IX6.2CG1WOB66WC39@kernel.org>

On Fri, Aug 21, 2026 at 03:54:44AM +0200, Danilo Krummrich wrote:
> usb_driver_claim_interface() is the only callsite in the kernel that
> does set dev->driver without a subsequent device_bind_driver().

Small correction, I think there are a few more. usb_port
(drivers/usb/core/port.c:782) sets dev->driver before device_register(),
and usb_port_driver has no ->match and no ->probe, so it depends entirely
on the __device_attach() dev->driver path to get bound. ccwgroup
(drivers/s390/cio/ccwgroup.c:385) and pata_parport
(drivers/ata/pata_parport/pata_parport.c:515) do the same. So that path
doesn't look USB-claim-specific, and if we ever want to remove it,
usb_port would need a ->match() first.

For the root cause, what about this: in usb_driver_claim_interface(),
when the interface isn't registered yet, just don't set dev->driver --
record the claim on struct usb_interface instead. Then, once the
interface gets added in usb_set_configuration(), bind it explicitly with
device_bind_driver(). That skips ->probe, which is exactly what
usb_audio's claim-now-bind-later needs, and it also attaches
knode_driver so teardown is safe. The __device_attach() path can stay
for w1/ccwgroup/pata_parport.

Does that sound reasonable?

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH v4] driver core: avoid klist_remove() on unattached knode_driver
@ 2026-08-24  4:46 Nguyen Quang Le Kien
  0 siblings, 0 replies; 16+ messages in thread
From: Nguyen Quang Le Kien @ 2026-08-24  4:46 UTC (permalink / raw)
  To: linux-usb
  Cc: Nguyen Quang Le Kien, Danilo Krummrich, Alan Stern, Greg KH,
	Rafael J . Wysocki, driver-core, linux-kernel,
	syzbot+87188222c77c0dbbdb4d, stable

In-Reply-To: <DKU2J83B6IX6.2CG1WOB66WC39@kernel.org>
References: <DKU2J83B6IX6.2CG1WOB66WC39@kernel.org>

On Fri, Aug 21, 2026 at 03:54:44AM +0200, Danilo Krummrich wrote:
> usb_driver_claim_interface() is the only callsite in the kernel that
> does set dev->driver without a subsequent device_bind_driver().

Small correction, I think there are a few more. usb_port
(drivers/usb/core/port.c:782) sets dev->driver before device_register(),
and usb_port_driver has no ->match and no ->probe, so it depends entirely
on the __device_attach() dev->driver path to get bound. ccwgroup
(drivers/s390/cio/ccwgroup.c:385) and pata_parport
(drivers/ata/pata_parport/pata_parport.c:515) do the same. So that path
doesn't look USB-claim-specific, and if we ever want to remove it,
usb_port would need a ->match() first.

For the root cause, what about this: in usb_driver_claim_interface(),
when the interface isn't registered yet, just don't set dev->driver --
record the claim on struct usb_interface instead. Then, once the
interface gets added in usb_set_configuration(), bind it explicitly with
device_bind_driver(). That skips ->probe, which is exactly what
usb_audio's claim-now-bind-later needs, and it also attaches
knode_driver so teardown is safe. The __device_attach() path can stay
for w1/ccwgroup/pata_parport.

Does that sound reasonable?

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

end of thread, other threads:[~2026-09-03  8:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20  5:55 [PATCH] driver core: avoid klist_remove() on unattached knode_driver Nguyen Quang Le Kien
2026-08-20  6:05 ` [PATCH v2] " Nguyen Quang Le Kien
2026-08-20  6:40   ` Greg KH
2026-08-20  6:56     ` Nguyen Quang Le Kien
2026-08-20  7:05       ` Greg Kroah-Hartman
2026-08-20  7:45     ` [PATCH v3] " Nguyen Quang Le Kien
2026-08-20  8:23       ` Greg Kroah-Hartman
2026-08-20  8:45         ` [PATCH v4] " Nguyen Quang Le Kien
2026-08-20  8:56           ` Greg KH
2026-08-20 16:14           ` Danilo Krummrich
2026-08-20 17:22             ` Alan Stern
2026-08-20 20:54               ` Danilo Krummrich
     [not found]                 ` <CAEe5be5OjseCMxGQP=QMd1L-muOTDguaay_-21moS1+xRNNNyw@mail.gmail.com>
2026-08-26 21:14                   ` Danilo Krummrich
2026-09-03  8:05                     ` Nguyen Quang Le Kien
  -- strict thread matches above, loose matches on Subject: below --
2026-08-24  4:41 Nguyen Quang Le Kien
2026-08-24  4:46 Nguyen Quang Le Kien

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.