From: sashiko-bot@kernel.org
To: "Tarun Sahu" <tarunsahu@google.com>
Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v19 4/7] driver core: do not always lock parent in shutdown
Date: Fri, 17 Jul 2026 02:59:12 +0000 [thread overview]
Message-ID: <20260717025913.067B41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716230411.2767394-5-tarunsahu@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Unprotected read of dev->parent introduces a Use-After-Free race with device_move() during reference acquisition.
Pre-existing issues:
- [High] Dropping and re-acquiring device_lock(dev) allows dev->parent to change, resulting in locking an obsolete parent.
--
--- Patch [4]: [PATCH v19 4/7] driver core: do not always lock parent in shutdown ---
commit 6be56e5bea0fe214a5199c9f806c49e62e60127f
Author: David Jeffery <djeffery@redhat.com>
driver core: do not always lock parent in shutdown
This patch modifies the device shutdown process to only lock a parent device
if it is strictly needed, rather than unconditionally. It also defers
acquiring a reference to the parent device until the point where the parent
needs to be locked.
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 82a7af1f3ba2e..31f95e86856e0 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
[ ... ]
> @@ -4925,12 +4921,32 @@ static void shutdown_one_device(struct device *dev)
> static void shutdown_one_device(struct device *dev)
> {
> + struct device *parent;
> +
> + device_lock(dev);
> +
> + /* use parent lock if needed to avoid race with probe/release */
> + if (dev->bus && dev->bus->need_parent_lock && dev->p && !dev->p->dead &&
> + (parent = get_device(dev->parent))) {
[Severity: High]
Does moving the parent reference acquisition out of the list_lock critical
section introduce a race condition where the parent could be freed?
In device_shutdown(), get_device(dev->parent) was previously called while
holding devices_kset->list_lock. Now that it is evaluated locklessly in
shutdown_one_device():
CPU1
shutdown_one_device()
evaluates dev->parent, but is preempted before get_device() is called
CPU2
device_move()
changes dev->parent and calls put_device(old_parent)
dropping the last reference and freeing the memory
When CPU1 resumes, could it pass the freed pointer into get_device() and
dereference it?
> + /* the parent lock needs to be acquired first, so re-lock */
> + device_unlock(dev);
> +
> + device_lock(parent);
> + device_lock(dev);
> +
> + __shutdown_one_device(dev);
[Severity: High]
This is a pre-existing issue, but does dropping and re-acquiring the device
lock here allow the topology to change?
If a concurrent device_move() reparents the device while device_lock(dev)
is dropped, it appears we might lock the obsolete parent. When we re-lock
dev and call __shutdown_one_device(), we haven't verified that dev->parent
still matches the locked parent.
Could this defeat the need_parent_lock synchronization and allow a
concurrent probe or release on the new parent to race with the shutdown?
> + device_unlock(dev);
> device_unlock(parent);
> + put_device(parent);
> + } else {
> + __shutdown_one_device(dev);
> + device_unlock(dev);
> + }
>
> put_device(dev);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716230411.2767394-1-tarunsahu@google.com?part=4
next prev parent reply other threads:[~2026-07-17 2:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 23:04 [PATCH v19 0/7] shut down devices asynchronously Tarun Sahu
2026-07-16 23:04 ` [PATCH v19 1/7] device_core: rely on put_device to free dev->p Tarun Sahu
2026-07-17 3:04 ` sashiko-bot
2026-07-16 23:04 ` [PATCH v19 2/7] driver core: Prevent device_add() during system shutdown Tarun Sahu
2026-07-17 3:15 ` sashiko-bot
2026-07-16 23:04 ` [PATCH v19 3/7] driver core: separate function to shutdown one device Tarun Sahu
2026-07-17 2:49 ` sashiko-bot
2026-07-16 23:04 ` [PATCH v19 4/7] driver core: do not always lock parent in shutdown Tarun Sahu
2026-07-17 2:59 ` sashiko-bot [this message]
2026-07-16 23:04 ` [PATCH v19 5/7] driver core: async device shutdown infrastructure Tarun Sahu
2026-07-17 2:51 ` sashiko-bot
2026-07-16 23:04 ` [PATCH v19 6/7] PCI: Enable async shutdown support Tarun Sahu
2026-07-17 2:56 ` sashiko-bot
2026-07-16 23:04 ` [PATCH v19 7/7] scsi: " Tarun Sahu
2026-07-17 3:00 ` 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=20260717025913.067B41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tarunsahu@google.com \
/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