[PATCH v2] driver core: bind a device with a preset driver even without autoprobe
From: Nguyen Ngoc Thang
Date: Thu Oct 08 2026 - 10:52:37 EST
usb_driver_claim_interface() may claim an interface that is not yet
registered, in which case it only sets dev->driver and relies on the
later device_add() to bind it via __device_attach(). With the bus
drivers_autoprobe disabled, device_initial_probe() skips the attach, so
the device is registered with dev->driver set but never added to the
driver's klist.
Releasing such a device (from usb_driver_release_interface() or from
sysfs unbind) makes __device_release_driver() call klist_remove() on an
unattached node and dereference a NULL klist:
KASAN: null-ptr-deref in range [0x58-0x5f]
RIP: klist_put+0x4d/0x1d0
klist_remove+0x14c/0x2e0
device_release_driver_internal+0x4fb/0x620
usb_driver_release_interface+0x10e/0x190
cdc_ncm_unbind+0x2ac/0x350
usbnet_disconnect+0x1e2/0x300
usb_unbind_interface+0x1dd/0x9e0
Autoprobe only governs matching drivers to devices; a device that
already has a driver needs no matching, just the bind that was promised
at claim time. Do not skip that bind.
Reported-by: syzbot+863936f50214e843ae0c@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=863936f50214e843ae0c
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@xxxxxxxxx>
---
v2: Sashiko pointed out that v1 only closed one entry point: a sysfs
unbind of the claimed-but-unbound data interface would still reach
klist_remove() on an unattached node. Fix the state itself instead:
bind the device when a driver was preset, as claim promised. v1 was
"USB: core: don't release an unbound claimed interface via the driver
core" (device_is_bound() in usb_driver_release_interface()), dropped.
Tested with the syzbot C reproducer in QEMU (KASAN, dummy_hcd). The
race that leaves the interface unbound is rare, so to make it
deterministic I temporarily made device_initial_probe() behave as if
autoprobe were off whenever dev->driver is set: the unpatched logic
oopses 3/3, with this patch 0/4. The plain patched kernel, without
the hack, shows no oops either.
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 f6525a7ee8c5..137bf1dea333 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1149,7 +1149,8 @@ void device_initial_probe(struct device *dev)
if (!sp)
return;
- if (sp->drivers_autoprobe)
+ /* a device with a preset driver must still be bound */
+ if (sp->drivers_autoprobe || dev->driver)
__device_attach(dev, true);
subsys_put(sp);
--
2.43.0