From: sashiko-bot@kernel.org
To: "Nguyen Ngoc Thang" <ngocthang2710.1999@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] driver core: bind a device with a preset driver even without autoprobe
Date: Thu, 08 Oct 2026 15:02:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-164330@kernel.org> (raw)
In-Reply-To: <20261008144859.25548-1-ngocthang2710.1999@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] driver core: lockless TOCTOU race in device_initial_probe() bypasses autoprobe=0
--
commit e63fcf260c7ac274ae164a5fb03accba2fcada52
Author: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
driver core: bind a device with a preset driver even without autoprobe
When drivers_autoprobe is disabled, device_initial_probe() skipped
calling __device_attach(). This commit ensures that devices with a
preset driver still undergo binding even if autoprobe is disabled,
preventing a NULL pointer dereference in klist_remove() on unbind.
Closes: https://syzkaller.appspot.com/bug?extid=863936f50214e843ae0c
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index f6525a7ee8c54..137bf1dea3333 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);
[Severity: Medium]
Does this lockless check of dev->driver introduce a TOCTOU race that
bypasses the autoprobe disabled state?
If sp->drivers_autoprobe is disabled, this code relies on dev->driver
being non-NULL to trigger __device_attach(). However, if dev->driver is
cleared concurrently (for instance, via a hardware disconnect or a sysfs
unbind), __device_attach() will see dev->driver as NULL under the
device lock.
When __device_attach() sees dev->driver as NULL, it takes the else branch
and executes the fallback bus_for_each_drv() probe:
drivers/base/dd.c:__device_attach() {
...
} else if (dev->driver) {
...
} else {
struct device_attach_data data = {
.dev = dev,
.check_async = allow_async,
.want_async = false,
};
...
ret = bus_for_each_drv(dev->bus, NULL, &data,
__device_attach_driver);
...
}
Will this cause an unintended auto-probe across all drivers on the bus,
violating the autoprobe=0 configuration?
>
> subsys_put(sp);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008144859.25548-1-ngocthang2710.1999@gmail.com?part=1
next prev parent reply other threads:[~2026-10-08 15:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 0:34 [PATCH] USB: core: don't release an unbound claimed interface via the driver core Nguyen Ngoc Thang
2026-10-08 0:49 ` sashiko-bot
2026-10-08 14:48 ` [PATCH v2] driver core: bind a device with a preset driver even without autoprobe Nguyen Ngoc Thang
2026-10-08 15:02 ` sashiko-bot [this message]
2026-10-08 16:12 ` [PATCH v3] " Nguyen Ngoc Thang
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-164330@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=ngocthang2710.1999@gmail.com \
--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