Linux USB
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: sashiko-reviews@lists.linux.dev
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 15/31] driver core: Add a compatibility API for manual driver attachment
Date: Mon, 23 Nov 2026 12:15:01 +0200	[thread overview]
Message-ID: <20261123101501.GM14811@unreal> (raw)
In-Reply-To: <sashiko-outbox-223901@kernel.org>

On Thu, Nov 19, 2026 at 07:29:34PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] driver core: dev->p dereferenced before dev_ready_to_probe()
>   check
> --
> 
> commit 25b9e856ab045cdfdef1969512d8e94dbd1559f4
> Author: Leon Romanovsky <leon@kernel.org>
> 
> driver core: Add a compatibility API for manual driver attachment
> 
> This commit adds device_driver_attach_unrestricted() and a per-device
> driver_lock mutex to serialize manual driver attachment, probing, removal,
> and deletion without requiring callers to hold the device mutex.
> 
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > index 52123251965de..6ac1486b9fbb5 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> [ ... ]
> > @@ -545,16 +560,85 @@ int device_bind_driver(struct device *dev)
> >  {
> >  	int ret;
> >  
> > -	ret = driver_sysfs_add(dev);
> > -	if (!ret) {
> > -		device_links_force_bind(dev);
> > -		driver_bound(dev);
> > +	mutex_lock(&dev->p->driver_lock);
> > +	ret = __device_bind_driver(dev);
> > +	mutex_unlock(&dev->p->driver_lock);
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(device_bind_driver);
> > +
> [ ... ]
> > +int device_driver_attach_unrestricted(const struct device_driver *drv,
> > +				      struct device *dev)
> > +{
> > +	int ret;
> > +
> > +	if (!device_is_registered(dev))
> > +		return -ENODEV;
> > +	if (!mutex_trylock(&dev->p->driver_lock))
> > +		return -EBUSY;
> > +	if (dev->p->dead) {
> > +		ret = -ENODEV;
> > +		goto unlock;
> > +	}
> > +	if (!dev_ready_to_probe(dev)) {
> > +		ret = -EAGAIN;
> > +		goto unlock;
> > +	}
> 
> [Severity: Medium]
> Can device_driver_attach_unrestricted() and device_bind_driver() hit a
> use-after-free or NULL pointer dereference on dev->p when device_add()
> fails?

The thing that it is pre-existing as well __driver_probe_device() has
the same order.

Thanks

> 
> In device_add(), kobject_add() sets dev->kobj.state_in_sysfs before the
> remaining fallible registration steps run, while dev_set_ready_to_probe()
> is only called after all of those steps succeed.  If any step in between
> fails, device_add() unwinds through name_error and frees dev->p without
> taking dev->p->driver_lock:
> 
> CPU0                                  CPU1
> device_add(dev)
>   kobject_add(&dev->kobj, ...)
>   ...
>                                       device_driver_attach_unrestricted()
>                                         device_is_registered(dev) -> true
>   dpm_sysfs_add(dev) -> fails
>   ...
>   kobject_del(&dev->kobj)
>   kfree(dev->p)
>   dev->p = NULL
>                                         mutex_trylock(&dev->p->driver_lock)
>                                           <-- use-after-free / NULL deref
> 
> Unlike waiting_for_supplier_show() in this commit, which checks
> dev_ready_to_probe(dev) (stored in dev->flags) before reading
> dev->p->dead, device_driver_attach_unrestricted() touches
> dev->p->driver_lock and dev->p->dead before checking
> dev_ready_to_probe(dev).  device_bind_driver() similarly locks
> dev->p->driver_lock without checking dev->p or dev_ready_to_probe(dev).
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com?part=15
> 

  reply	other threads:[~2026-11-23 10:15 UTC|newest]

Thread overview: 71+ 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-23  6:24     ` Leon Romanovsky
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-23  7:41     ` Leon Romanovsky
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-23  8:48     ` Leon Romanovsky
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-23  9:22     ` Leon Romanovsky
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-23 10:15     ` Leon Romanovsky [this message]
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=20261123101501.GM14811@unreal \
    --to=leon@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --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