From: sashiko-bot@kernel.org
To: "Johan Hovold" <johan@kernel.org>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v3] driver core: take parent lock in async device attach
Date: Tue, 13 Oct 2026 14:23:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-169899@kernel.org> (raw)
In-Reply-To: <20261013140408.1226841-1-johan@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] driver-core: UAF on dev->parent in async device attach
--
commit c5f34060c20ab88f32e94e3a0ebf364f523925ee
Author: Mario Peter <mario.peter@leica-geosystems.com>
driver core: take parent lock in async device attach
On buses with need_parent_lock set (only USB), probe() must run with the
parent device locked. A synchronous attach after device_add() gets this
from the caller, e.g. usb_set_configuration() holds the udev lock while
adding interfaces.
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index f6525a7ee8c54..9dc7cce9bd8d2 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
[ ... ]
> @@ -1029,6 +1029,38 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
> return ret == 0;
> }
>
> +/*
> + * __device_driver_lock - acquire locks needed to manipulate dev->drv
> + * @dev: Device we will update driver info for
> + * @parent: Parent device. Needed if the bus requires parent lock
> + *
> + * This function will take the required locks for manipulating dev->drv.
> + * Normally this will just be the @dev lock, but when called for a USB
> + * interface, @parent lock will be held as well.
> + */
> +static void __device_driver_lock(struct device *dev, struct device *parent)
> +{
> + if (parent && dev->bus->need_parent_lock)
> + device_lock(parent);
[Severity: High]
Could this acquire a mutex within freed parent memory?
If this is called with a dangling parent pointer from
__device_attach_async_helper(), this will dereference the freed memory.
[ ... ]
> @@ -1038,7 +1070,7 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
> .want_async = true,
> };
>
> - device_lock(dev);
> + __device_driver_lock(dev, dev->parent);
[Severity: High]
Can this cause a use-after-free on dev->parent?
In the device removal path, device_del() sets dev->p->dead to true via
kill_device() and later drops the child's reference to dev->parent via
put_device(dev->parent).
If the parent device is also being removed and its final reference is dropped,
the parent could be freed.
If this async worker runs delayed, taking the lock before checking
dev->p->dead could pass a dangling dev->parent pointer. Prior to this patch,
device_lock(dev) was called, and dev->parent was never accessed if
dev->p->dead was true.
>
> /*
> * Check if device has already been removed or claimed. This may
> @@ -1060,7 +1092,7 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
> if (dev->parent)
> pm_runtime_put(dev->parent);
> out_unlock:
> - device_unlock(dev);
> + __device_driver_unlock(dev, dev->parent);
[Severity: High]
If dev->parent was freed before the dev->p->dead check above, wouldn't this
unlock path also dereference the same dangling pointer?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013140408.1226841-1-johan@kernel.org?part=1
next prev parent reply other threads:[~2026-10-13 14:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 14:04 [PATCH v3] driver core: take parent lock in async device attach Johan Hovold
2026-10-13 14:23 ` sashiko-bot [this message]
2026-10-13 15:41 ` PETER Mario
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-169899@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=johan@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