Linux USB
 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 31/31] USB: Authorize devices through device trust
Date: Thu, 19 Nov 2026 19:29:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-223917@kernel.org> (raw)
In-Reply-To: <20261118-device-trust-core-v3-31-d655875c4bfb@nvidia.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] usb: core: missing usb_notify_remove_device() when
  disconnecting unbound device
- [Low] usb: stale config_error in usb_authorize_device() when no config
  is chosen
- [Low] usb: core: missing device_trust_init() before
  trace_usb_alloc_dev()
--

commit 6534edcb6b352edce6df3458c65d3d073e695248
Author: Leon Romanovsky <leon@kernel.org>

USB: Authorize devices through device trust

This commit integrates USB device authorization with the generic device
trust policy framework, deferring driver binding and configuration for
unauthorized devices until their trust policy is updated and keeping
authorization and configuration result tracking under the device lock.

> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index 199d3f535a891..62eedae9d0077 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c

[ ... ]

> @@ -2784,17 +2785,41 @@ int usb_deauthorize_device(struct usb_device *usb_dev)
>  
>  int usb_authorize_device(struct usb_device *usb_dev)
>  {
> +	bool attach;
>  	int result = 0, c;
>  
>  	usb_lock_device(usb_dev);
> -	if (usb_dev->authorized == 1)
> -		goto out_authorized;
> +	if (device_policy_is_blocked(&usb_dev->dev)) {
> +		result = device_trust_set_policy_locked(&usb_dev->dev,
> +							DEVICE_TRUST_POLICY_UNRESTRICTED);
> +		if (result)
> +			goto out_unlock;
> +	}
> +
> +	attach = device_trust_enabled() && !usb_dev->dev.driver;
> +	if (!attach && usb_dev->authorized == 1 &&
> +	    (!device_trust_enabled() || !usb_dev->config_error ||
> +	     usb_dev->actconfig))
> +		goto out_unlock;
>  
>  	result = usb_autoresume_device(usb_dev);
>  	if (result < 0) {
>  		dev_err(&usb_dev->dev,
>  			"can't autoresume for authorization: %d\n", result);
> -		goto error_autoresume;
> +		goto out_unlock;
> +	}
> +
> +	if (attach) {
> +		usb_dev->authorized = 1;
> +		usb_dev->config_error = 0;
> +		result = device_attach_locked(&usb_dev->dev);
> +		if (result <= 0) {
> +			if (result >= 0)
> +				result = -ENODEV;
> +		} else {
> +			result = usb_dev->config_error;
> +		}
> +		goto out_autosuspend;
> +	}
>  
>  	usb_dev->authorized = 1;
>  	/* Choose and set the configuration.  This registers the interfaces
>  	 * with the driver core and lets interface drivers bind to them.
>  	 */
>  	c = usb_choose_configuration(usb_dev);
>  	if (c >= 0) {
>  		result = usb_set_configuration(usb_dev, c);

[Severity: Low]
Should the non-attach path also clear usb_dev->config_error = 0 before
calling usb_choose_configuration()?

If a prior configuration attempt failed (leaving usb_dev->config_error
non-zero and usb_dev->actconfig NULL) and usb_choose_configuration()
returns -1, usb_set_configuration() is not called and config_error stays
non-zero.  Subsequent calls to usb_authorize_device() on the already
authorized device will then bypass the early return and repeatedly
autoresume the device and re-run configuration selection.

> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 2559a180fdeec..ed71f1155e2ed 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -748,6 +748,11 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
>  #endif
>  
>  	dev->authorized = usb_dev_authorized(dev, usb_hcd);
> +	if (device_trust_enabled()) {
> +		if (!dev->authorized)
> +			dev->dev.trust_policy = DEVICE_TRUST_POLICY_BLOCKED;
> +		dev->authorized = 1;
> +	}
>  	trace_usb_alloc_dev(dev);
>  	return dev;
>  }

[Severity: High]
Does leaving a trust-blocked USB device unbound skip
usb_notify_remove_device() if the device is disconnected before being
authorized?

With DEVICE_TRUST_POLICY_BLOCKED, device_add() in usb_new_device()
creates the /dev/bus/usb/BBB/DDD node, but device_trust_prepare()
rejects binding usb_generic_driver, leaving udev->dev.driver NULL.
Userspace can still open the usbfs node via usbdev_open(), which adds a
struct usb_dev_state entry to udev->filelist.  If the device is then
unplugged before authorization, device_del() in usb_disconnect() does
not run usb_generic_driver_disconnect(), which is the only caller of
usb_notify_remove_device():

drivers/usb/core/generic.c:usb_generic_driver_disconnect() {
	usb_notify_remove_device(udev);
	usb_release_bos_descriptor(udev);
}

As a result, usbdev_remove() never runs, udev->filelist is not drained,
disconnect signals are not delivered, and tasks waiting in poll(),
USBDEVFS_REAPURB, or USBDEVFS_WAIT_FOR_RESUME hang indefinitely.

[Severity: Low]
Does trace_usb_alloc_dev() record usb_device_authorized() before
device_trust_init() has applied any boot trust rules?

device_trust_init(&udev->dev) is not called until device_add() in
usb_new_device(), so trace_usb_alloc_dev() and the early
trace_usb_set_device_state() events during enumeration evaluate
dev->dev.trust_policy before device_trust.default= or device_trust= boot
policies take effect.

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

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

Thread overview: 66+ 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 19:29   ` 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
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 [this message]

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-223917@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