From: sashiko-bot@kernel.org
To: "Rihyeon Kim" <rihyeon8648@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: Handle dev_set_name() failure in pci_setup_device()
Date: Sat, 25 Jul 2026 10:57:35 +0000 [thread overview]
Message-ID: <20260725105735.F3C6C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725104747.226575-1-rihyeon8648@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unhandled device_add() failure in pci_device_add() leaves a corrupt device on bus->devices, triggering NULL pointer dereferences.
--
--- Patch [1]: [PATCH] PCI: Handle dev_set_name() failure in pci_setup_device() ---
commit a0f24b9a341960f58d26143c84bb644d8d2b737e
Author: Rihyeon Kim <rihyeon8648@gmail.com>
PCI: Handle dev_set_name() failure in pci_setup_device()
This commit checks the return value of dev_set_name() during
pci_setup_device() to prevent enumeration of unnamed devices. By
propagating the error early, it avoids a later failure in device_add()
that would trigger a NULL pointer dereference.
Reported-by: syzbot+87bb32e345aa80c0554b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=87bb32e345aa80c0554b
Tested-by: syzbot+87bb32e345aa80c0554b@syzkaller.appspotmail.com
> Two things I noticed while working on this and deliberately left alone,
> since they look like separate changes:
[ ... ]
> - pci_device_add() ignores device_add() failure entirely; the WARN_ON() is
> all there is and the half-added device stays on bus->devices. I built a
> kernel with [2] applied (it stops device_add() from freeing dev->p) and
> the NULL dereference above does go away, but the WARNING and the stale
> bus->devices entry remain. Happy to follow up on that separately if you
> think it is worth doing.
[Severity: High]
This is a pre-existing issue, but should the failure of device_add() in
pci_device_add() be handled with explicit error paths instead of just
emitting a warning?
When device_add() fails, it cleans up and frees dev->p:
drivers/pci/probe.c:pci_device_add() {
...
ret = device_add(&dev->dev);
WARN_ON(ret < 0);
...
}
Leaving the initialized device on the globally visible bus->devices list
allows pci_bus_add_devices() to iterate over it and pass it to
__device_attach().
Could this result in a kernel panic when __device_attach() unconditionally
dereferences the freed dev->p?
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index dd0abbc63e18d..474c6cb327be5 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725104747.226575-1-rihyeon8648@gmail.com?part=1
next prev parent reply other threads:[~2026-07-25 10:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 10:47 [PATCH] PCI: Handle dev_set_name() failure in pci_setup_device() Rihyeon Kim
2026-07-25 10:57 ` sashiko-bot [this message]
2026-07-25 19:19 ` Krzysztof Wilczyński
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=20260725105735.F3C6C1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.