From: sashiko-bot@kernel.org
To: "Leon Romanovsky" <leon@kernel.org>
Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
linux-pci@vger.kernel.org, linux-sound@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3 06/31] USB: Release interface claims according to binding state
Date: Thu, 19 Nov 2026 19:29:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-223892@kernel.org> (raw)
In-Reply-To: <20261118-device-trust-core-v3-6-d655875c4bfb@nvidia.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] usb: core: pre-claimed interface with autoprobe off crashes
on core unbind
- [Medium] usb: core: NULL dereference in usb_driver_release_interface()
when driver is NULL
--
commit 03347cb54cf6030265378e68aba157a23982255b
Author: Leon Romanovsky <leon@kernel.org>
USB: Release interface claims according to binding state
This commit updates usb_driver_release_interface() to check
device_is_bound() instead of device_is_registered() before releasing an
interface through the driver core, and holds the device lock while
checking and unbinding unclaimed interfaces.
> diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
> index 735ae3310b45d..926f63cd2c834 100644
> --- a/drivers/usb/core/driver.c
> +++ b/drivers/usb/core/driver.c
> @@ -612,6 +612,15 @@ int usb_driver_claim_interface(struct usb_driver *driver,
> }
> EXPORT_SYMBOL_GPL(usb_driver_claim_interface);
>
> +static void usb_unbind_claim(struct usb_interface *iface)
> +{
> + struct device *dev = &iface->dev;
> +
> + usb_unbind_interface(dev);
> + dev_set_drvdata(dev, NULL);
> + dev->driver = NULL;
> +}
> +
> /**
> * usb_driver_release_interface - unbind a driver from an interface
> * @driver: the driver to be unbound
> @@ -631,27 +640,25 @@ void usb_driver_release_interface(struct usb_driver *driver,
> {
> struct device *dev = &iface->dev;
>
> - /* this should never happen, don't release something that's not ours */
> - if (!dev->driver || dev->driver != &driver->driver)
> - return;
> -
> - /* don't release from within disconnect() */
> + /* Avoid recursive locking from disconnect(). */
> if (iface->condition != USB_INTERFACE_BOUND)
> return;
> +
> + device_lock(dev);
> + if (dev->driver != &driver->driver ||
> + iface->condition != USB_INTERFACE_BOUND)
> + goto unlock;
[Severity: Medium]
Can dropping the !dev->driver check cause a NULL pointer dereference in
usb_unbind_interface()?
When intf->dev.driver is NULL, usb_forced_unbind_intf() passes driver =
to_usb_driver(NULL), whose &driver->driver member address evaluates back
to NULL, making dev->driver != &driver->driver false. If an interface is
claimed before registration and registered while drivers_autoprobe is
disabled, device_add() succeeds with iface->condition ==
USB_INTERFACE_BOUND and device_is_bound(dev) == false (so the unwind in a
later commit "USB: Unwind interface claims after registration or binding
failure" does not run); if a subsequent __device_attach() fails in
device_bind_driver(), it clears dev->driver to NULL while leaving
iface->condition as USB_INTERFACE_BOUND. Calling
usb_deauthorize_interface() -> usb_forced_unbind_intf() on that interface
then passes the guard and dereferences to_usb_driver(NULL) in
usb_unbind_claim() -> usb_unbind_interface().
> iface->condition = USB_INTERFACE_UNBINDING;
>
> - /* Release via the driver core only if the interface
> - * has already been registered
> - */
> - if (device_is_registered(dev)) {
> - device_release_driver(dev);
> - } else {
> - device_lock(dev);
> - usb_unbind_interface(dev);
> - dev_set_drvdata(dev, NULL);
> - dev->driver = NULL;
> + if (device_is_bound(dev)) {
> device_unlock(dev);
> + device_release_driver(dev);
> + return;
> }
> +
> + usb_unbind_claim(iface);
> +unlock:
> + device_unlock(dev);
> }
> EXPORT_SYMBOL_GPL(usb_driver_release_interface);
[Severity: Medium]
What happens if a pre-claimed sibling interface registered with
drivers_autoprobe disabled is detached through the driver core rather
than usb_driver_release_interface()?
When device_add() registers a pre-claimed interface while
sp->drivers_autoprobe is 0, device_initial_probe() skips
__device_attach(), leaving the interface registered on the bus with
dev->driver set and dev->p->knode_driver unattached (which the later
commit "USB: Unwind interface claims after registration or binding
failure" does not unwind because device_add() returns 0 and dev->driver
is non-NULL). If that sibling interface is then unbound directly via
sysfs unbind_store() -> device_driver_detach() ->
__device_release_driver(), or removed by usb_disable_device() ->
device_del() for drivers such as snd-usb-audio that do not call
usb_driver_release_interface() in disconnect(), __device_release_driver()
sees dev->driver != NULL and calls klist_remove(&dev->p->knode_driver) on
the unattached node, causing a NULL pointer dereference. For drivers
that do not call usb_driver_release_interface() on disconnect,
driver_unregister() -> driver_detach() also misses the interface because
it is not on drv->p->klist_devices, leaving dev->driver as a dangling
pointer after module unload.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com?part=6
next prev parent reply other threads:[~2026-11-19 19:29 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 19:26 [PATCH v3 00/31] driver core: Authorize device trust before driver binding Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 01/31] wifi: mac80211_hwsim: lock device for manual " Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 02/31] Bluetooth: btusb: Fix MediaTek ISO claim locking Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 03/31] USB: Lock interfaces during manual driver binding Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 04/31] USB: serial: Register USB drivers with their owning module Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 05/31] USB: Reject claims of DT-disabled interfaces Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 06/31] USB: Release interface claims according to binding state Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot [this message]
2026-11-18 19:26 ` [PATCH v3 07/31] USB: Reject claims after interface registration failure Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 08/31] ALSA: usb-audio: Release interface claims when probe fails Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 09/31] USB: Pin modules for unregistered interface claims Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 10/31] USB: Add helpers to release unpublished " Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 11/31] USB: Unwind interface claims after registration or binding failure Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 12/31] PNP: Attach card devices through the driver core Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 13/31] cdx: Propagate DMA configuration errors Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 14/31] driver core: Report deferred probes through sysfs drivers_probe Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 15/31] driver core: Add a compatibility API for manual driver attachment Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 16/31] Input: gameport - use the compatibility driver attachment API Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 17/31] Input: serio " Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 18/31] net: phy: Use " Leon Romanovsky
2026-11-18 20:21 ` Andrew Lunn
2026-11-19 7:18 ` Leon Romanovsky
2026-11-19 13:30 ` Andrew Lunn
2026-11-18 19:26 ` [PATCH v3 19/31] driver core: Introduce a generic device trust level Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 20/31] driver core: Expose device trust authorization interfaces Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 21/31] driver core: Accept device trust policy on the kernel command line Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 22/31] driver core: Accept device trust policy by driver name Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 23/31] driver core: Expose committed device trust level Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 24/31] driver core: Cover trust authorization and binding with KUnit Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 25/31] driver core: Document trust admission and initrd authorization Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 26/31] PCI: Use device trust for platform restrictions Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 27/31] iommu: Use device trust for DMA restrictions Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 28/31] driver core: Allow driver attachment with the device lock held Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 29/31] USB: Retain the result of configuration requests Leon Romanovsky
2026-11-18 19:27 ` [PATCH v3 30/31] USB: Authorize interfaces through device trust Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
2026-11-18 19:27 ` [PATCH v3 31/31] USB: Authorize devices " Leon Romanovsky
2026-11-19 19:29 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-223892@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=leon@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox