All of lore.kernel.org
 help / color / mirror / Atom feed
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 11/31] USB: Unwind interface claims after registration or binding failure
Date: Thu, 19 Nov 2026 19:29:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-223897@kernel.org> (raw)
In-Reply-To: <20261118-device-trust-core-v3-11-d655875c4bfb@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] USB: unbound claim missed in usb_set_configuration() when
  autoprobe is off
- [Medium] usb: core: failed interface claim unwind skips altsetting 0
  reset
--

commit 5e9d278c3fe83635c408aabb0f7fdb4a22c1316b
Author: Leon Romanovsky <leon@kernel.org>

USB: Unwind interface claims after registration or binding failure

This commit unwinds pre-claimed USB interfaces when device_add() fails or
driver binding does not complete during usb_set_configuration(), and releases
remaining unregistered interface claims in usb_disable_device().

> diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
> index 306978caaf1ef..b2e5ed35a4a59 100644
> --- a/drivers/usb/core/message.c
> +++ b/drivers/usb/core/message.c

[ ... ]

> @@ -2270,6 +2292,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
>  	 */
>  	for (i = 0; i < nintf; ++i) {
>  		struct usb_interface *intf = cp->interface[i];
> +		struct device_driver *claimant;
>  		struct module *claim_owner;
>  
>  		if (intf->dev.of_node &&
> @@ -2285,6 +2308,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
>  			intf->cur_altsetting->desc.bInterfaceNumber);
>  		device_enable_async_suspend(&intf->dev);
>  		device_lock(&intf->dev);
> +		claimant = intf->dev.driver;
>  		claim_owner = xchg(&intf->claim_owner, NULL);
>  		device_unlock(&intf->dev);
>  		ret = device_add(&intf->dev);
> @@ -2293,7 +2317,22 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
>  			intf->unregistering = 1;
>  			device_unlock(&intf->dev);
>  		}

[Severity: Medium]
Does setting intf->unregistering = 1 before calling
usb_driver_release_refused_claim() prevent usb_unbind_interface() from
resetting the interface back to altsetting 0?

When a driver such as cdc_ncm claims a sibling data interface and switches it
to a non-zero alternate setting during probe(), a later device_add() failure
on that sibling sets intf->unregistering = 1 before
usb_driver_release_refused_claim() runs usb_unbind_interface().  Inside
usb_unbind_interface(), driver->disconnect() releases the control interface
and usb_set_interface() is called to restore altsetting 0, but
usb_set_interface() rejects the request with -ENODEV because
iface->unregistering is already set.  Since disconnect() released the sibling
claim, usb_has_claimant() returns false and the device stays configured with
the failed interface and its HCD bandwidth stuck on the non-zero altsetting.

> -		module_put(claim_owner);
> +		if (claimant && (ret || !intf->dev.driver) &&
> +		    usb_driver_release_refused_claim(intf, claimant)) {
> +			bool unconfigure = usb_has_claimant(dev, claimant);
> +
> +			get_device(&intf->dev);
> +			if (unconfigure)
> +				usb_set_configuration(dev, -1);
> +			module_put(claim_owner);
> +			put_device(&intf->dev);
> +			if (unconfigure) {
> +				usb_autosuspend_device(dev);
> +				return ret ? ret : -ENODEV;
> +			}
> +		} else {
> +			module_put(claim_owner);
> +		}

[Severity: Medium]
Can checking (ret || !intf->dev.driver) without device_lock(&intf->dev) miss
an unbound claim when drivers_autoprobe is disabled?

If an unregistered sibling interface was claimed during an earlier probe() and
bus autoprobing is disabled before device_add() runs device_initial_probe(),
__device_attach() is skipped:

drivers/base/dd.c:device_initial_probe() {
	if (sp->drivers_autoprobe) {
		ret = __device_attach(dev, true);
		if (ret == 2)
			__device_attach(dev, false);
	}
}

device_add() then returns 0 with intf->dev.driver still pointing to claimant
while device_is_bound(&intf->dev) is false.  Because (ret ||
!intf->dev.driver) is false, usb_set_configuration() skips
usb_driver_release_refused_claim() and drops claim_owner in the else branch.
When usb_disable_device() later runs, device_is_registered(&interface->dev) is
true, so device_del() is called before usb_release_unregistered_interface()
and __device_release_driver() calls klist_remove(&dev->p->knode_driver) on an
unattached klist_node, causing a NULL pointer dereference in klist_put().

Checking !device_is_bound(&intf->dev) under device_lock(&intf->dev) inside
usb_driver_release_refused_claim() instead of the unlocked !intf->dev.driver
check would catch this case.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com?part=11

  reply	other threads:[~2026-11-19 19:29 UTC|newest]

Thread overview: 67+ 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-19  0:32   ` driver core: Authorize device trust before " bluez.test.bot
2026-11-19 19:29   ` [PATCH v3 01/31] wifi: mac80211_hwsim: lock device for manual " sashiko-bot
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-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 04/31] USB: serial: Register USB drivers with their owning module Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 05/31] USB: Reject claims of DT-disabled interfaces Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
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
2026-11-18 19:26 ` [PATCH v3 07/31] USB: Reject claims after interface registration failure Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 08/31] ALSA: usb-audio: Release interface claims when probe fails Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
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-19 19:29   ` sashiko-bot
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 [this message]
2026-11-18 19:26 ` [PATCH v3 12/31] PNP: Attach card devices through the driver core Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 13/31] cdx: Propagate DMA configuration errors Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 14/31] driver core: Report deferred probes through sysfs drivers_probe Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
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-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 17/31] Input: serio " Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
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-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 19/31] driver core: Introduce a generic device trust level Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 20/31] driver core: Expose device trust authorization interfaces Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 21/31] driver core: Accept device trust policy on the kernel command line Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 22/31] driver core: Accept device trust policy by driver name Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 23/31] driver core: Expose committed device trust level Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
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-19 19:29   ` sashiko-bot
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-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 28/31] driver core: Allow driver attachment with the device lock held Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 29/31] USB: Retain the result of configuration requests Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
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-223897@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 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.