From: sashiko-bot@kernel.org
To: "Rihyeon Kim" <rihyeon8648@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 1/2] PCI: Handle dev_set_name() failure in pci_setup_device()
Date: Sun, 26 Jul 2026 09:49:03 +0000 [thread overview]
Message-ID: <20260726094904.376D11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726093200.146111-2-rihyeon8648@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch prevents a specific failure in `device_add()` (NULL name) but fails to address the systemic bug in `pci_device_add()` where `device_add()` failures are ignored, which leaves structurally invalid devices on `bus->devices` and continues to allow NULL pointer dereference panics.
--
--- Patch [1]: [PATCH v2 1/2] PCI: Handle dev_set_name() failure in pci_setup_device() ---
commit 91ceaf734e6165d4ec69baadee524cce3c4d990d
Author: Rihyeon Kim <rihyeon8648@gmail.com>
PCI: Handle dev_set_name() failure in pci_setup_device()
The commit adds error handling for dev_set_name() in pci_setup_device() to
prevent it from continuing with a NULL name. This avoids a later panic where
device_add() rejects the unnamed device but pci_device_add() ignores the
failure, leaving the invalid device on bus->devices with a freed dev->p.
Link: https://syzkaller.appspot.com/bug?extid=87bb32e345aa80c0554b
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index dd0abbc63e18d..3e6f0eb7d456c 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
[ ... ]
> @@ -2052,9 +2053,13 @@ int pci_setup_device(struct pci_dev *dev)
> */
> dev->msi_addr_mask = DMA_BIT_MASK(64);
>
> - dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
> - dev->bus->number, PCI_SLOT(dev->devfn),
> - PCI_FUNC(dev->devfn));
> + err = dev_set_name(&dev->dev, "%04x:%02x:%02x.%d",
> + pci_domain_nr(dev->bus), dev->bus->number,
> + PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
> + if (err) {
> + pci_release_of_node(dev);
> + return err;
> + }
[Severity: High]
This isn't a bug introduced by this patch, but while this change prevents
one trigger for the NULL pointer dereference, does it fully fix the
underlying vulnerability in pci_device_add()?
As the commit message describes, if device_add() fails, it frees dev->p
but pci_device_add() leaves the structurally invalid device on bus->devices,
which later causes __device_attach() to panic.
Since device_add() can fail for other reasons beyond an invalid name (such
as -ENOMEM or sysfs naming conflicts), won't those other failures still
trigger the exact same NULL pointer dereference?
In drivers/pci/probe.c:pci_device_add():
ret = device_add(&dev->dev);
WARN_ON(ret < 0);
If device_add() fails here for a different reason, it only triggers a
warning while leaving the device on the list.
Should pci_device_add() also be updated to properly remove the device from
bus->devices when device_add() fails?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260726093200.146111-1-rihyeon8648@gmail.com?part=1
next prev parent reply other threads:[~2026-07-26 9:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 9:31 [PATCH v2 0/2] PCI: Fix dev_set_name() error handling in pci_setup_device() Rihyeon Kim
2026-07-26 9:31 ` [PATCH v2 1/2] PCI: Handle dev_set_name() failure " Rihyeon Kim
2026-07-26 9:49 ` sashiko-bot [this message]
2026-07-26 9:32 ` [PATCH v2 2/2] PCI: Free the device name on the pci_setup_device() error path Rihyeon Kim
2026-07-26 9:43 ` 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=20260726094904.376D11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rihyeon8648@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