Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Jeffery" <djeffery@redhat.com>
Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH 4/5] PCI: Enable async shutdown support
Date: Tue, 16 Jun 2026 15:38:53 +0000	[thread overview]
Message-ID: <20260616153853.EC8F91F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260616152219.6268-5-djeffery@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Double `put_device()` on `bridge->dev` in the `pci_register_host_bridge()` error path leads to use-after-free.
- [High] Unlocked read-modify-write of C bitfields in `dev_pm_info` via sysfs can clobber PM core states like `in_dpm_list`.
--

commit 5968194913e4b5e2b73a45e8bbc2ab20340b2cfe
Author: David Jeffery <djeffery@redhat.com>

PCI: Enable async shutdown support

This commit allows PCI device shutdown to be performed asynchronously.
It introduces calls to dev_set_async_shutdown() during host bridge
registration and device addition to reduce overall shutdown time.

> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index b3cefec25f518..4782b4d5306b6 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1046,6 +1046,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
>  
>  	bus->bridge = get_device(&bridge->dev);
>  	device_enable_async_suspend(bus->bridge);

[Severity: High]
This is a pre-existing issue, but does writing to the power/async sysfs
file trigger an unlocked read-modify-write that can clobber PM core states?

struct dev_pm_info declares adjacent bitfields async_suspend:1 and
in_dpm_list:1 that share a memory word.

device_pm_add() performs a locked read-modify-write under dpm_list_mtx to set
dev->power.in_dpm_list = true.

Because dpm_sysfs_add(dev) executes before device_pm_add(dev) during
initialization, userspace can immediately trigger a concurrent lockless
read-modify-write by writing to the power/async sysfs file. This calls
async_store() -> device_enable_async_suspend() and sets
dev->power.async_suspend = true without holding any locks.

If this lockless RMW races with device_pm_add(), can it overwrite in_dpm_list
back to false after it was set, breaking PM dependency chains and aborting
device linking?

[Severity: Critical]
This is a pre-existing issue, but does the error path in
pci_register_host_bridge() trigger a double put_device() on bridge->dev?

If device_register(&bus->dev) fails, execution jumps to the unregister label
which explicitly drops the bridge->dev reference:

unregister:
	put_device(&bridge->dev);
	device_del(&bridge->dev);
free:
	...
	if (bus_registered)
		put_device(&bus->dev);

However, the release function for the bus, release_pcibus_dev(), also
unconditionally drops the bridge reference:

static void release_pcibus_dev(struct device *dev)
{
	struct pci_bus *pci_bus = to_pci_bus(dev);

	put_device(pci_bus->bridge);
	...
}

When the execution falls through to the free label and calls
put_device(&bus->dev), will release_pcibus_dev() drop the bridge->dev
reference a second time, potentially causing a use-after-free when the caller
handles the registration error?

> +	dev_set_async_shutdown(bus->bridge);
>  	pci_set_bus_of_node(bus);
>  	pci_set_bus_msi_domain(bus);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260616152219.6268-1-djeffery@redhat.com?part=4

  reply	other threads:[~2026-06-16 15:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-16 15:22 [PATCH v17 0/5] shut down devices asynchronously David Jeffery
2026-06-16 15:22 ` [PATCH 1/5] driver core: separate function to shutdown one device David Jeffery
2026-06-16 15:34   ` sashiko-bot
2026-06-16 15:22 ` [PATCH 2/5] driver core: do not always lock parent in shutdown David Jeffery
2026-06-16 15:38   ` sashiko-bot
2026-06-16 15:22 ` [PATCH 3/5] driver core: async device shutdown infrastructure David Jeffery
2026-06-16 15:39   ` sashiko-bot
2026-06-16 16:10   ` David Jeffery
2026-06-16 17:26   ` Randy Dunlap
2026-06-16 15:22 ` [PATCH 4/5] PCI: Enable async shutdown support David Jeffery
2026-06-16 15:38   ` sashiko-bot [this message]
2026-06-16 15:22 ` [PATCH 5/5] scsi: " David Jeffery
2026-06-16 15:44   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-05-18 19:31 [PATCH v16 0/5] shut down devices asynchronously David Jeffery
2026-05-18 19:32 ` [PATCH 4/5] PCI: Enable async shutdown support David Jeffery
2026-04-29 17:50 [PATCH v15 0/5] shut down devices asynchronously David Jeffery
2026-04-29 17:50 ` [PATCH 4/5] PCI: Enable async shutdown support David Jeffery
2026-05-06 18:28   ` Bjorn Helgaas
2026-05-06 21:10     ` David Jeffery
2026-05-06 21:24       ` Bjorn Helgaas
2026-04-20 15:26 [PATCH v14 0/5] shut down devices asynchronously David Jeffery
2026-04-20 15:26 ` [PATCH 4/5] PCI: Enable async shutdown support David Jeffery
2026-04-07 15:35 [PATCH v13 0/5] shut down devices asynchronously David Jeffery
2026-04-07 15:35 ` [PATCH 4/5] PCI: Enable async shutdown support David Jeffery
2026-03-19 14:11 [PATCH v12 0/5] shut down devices asynchronously David Jeffery
2026-03-19 14:11 ` [PATCH 4/5] PCI: enable async shutdown support David Jeffery
2026-03-11 17:12 [PATCH 1/5] driver core: do not always lock parent in shutdown David Jeffery
2026-03-11 17:12 ` [PATCH 4/5] pci: enable async shutdown support David Jeffery
2026-03-11 23:08   ` Bjorn Helgaas
2026-03-12 13:46     ` David Jeffery
2026-03-12  5:09   ` Greg Kroah-Hartman
2026-03-12 13:54     ` David Jeffery

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=20260616153853.EC8F91F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=djeffery@redhat.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@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