From: sashiko-bot@kernel.org
To: "Aditya Gupta" <adityag@linux.ibm.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v3] PCI: pnv_php: Add null checks for OpenCAPI PHBs
Date: Tue, 09 Jun 2026 09:05:48 +0000 [thread overview]
Message-ID: <20260609090549.B845F1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260609084903.1352581-1-adityag@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] NULL pointer dereference in `pnv_php_alloc_slot()` during error handling.
- [High] Lockless iteration over PCI bus lists risks memory corruption.
- [High] Data race on `php_slot->irq` can lead to a double `free_irq()`.
- [High] Lockless modification of `php_slot->state` leads to TOCTOU races.
--
commit 72170284e1b2c84d6ca9a8f9f30c4d6aaa2d9c12
Author: Aditya Gupta <adityag@linux.ibm.com>
PCI: pnv_php: Add null checks for OpenCAPI PHBs
For OpenCAPI phb direct slots, the .pdev for php_slots will be NULL.
Various sections of the code in pnv_php can do a null dereference and
crash the kernel. Add null checks to prevent the null dereferences.
Cc: stable@vger.kernel.org
Fixes: 80f9fc236279 ("PCI: pnv_php: Work around switches with broken presence detection")
> diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
> index ff92a5c301b81..d0f5e8ad1f716 100644
> --- a/drivers/pci/hotplug/pnv_php.c
> +++ b/drivers/pci/hotplug/pnv_php.c
> @@ -47,6 +47,9 @@ static void pnv_php_disable_irq(struct pnv_php_slot *php_slot,
> struct pci_dev *pdev = php_slot->pdev;
> u16 ctrl;
>
> + if (!pdev)
> + return;
> +
> if (php_slot->irq > 0) {
> pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &ctrl);
> ctrl &= ~(PCI_EXP_SLTCTL_HPIE |
> PCI_EXP_SLTCTL_PDCE |
> PCI_EXP_SLTCTL_DLLSCE);
> pcie_capability_write_word(pdev, PCI_EXP_SLTCTL, ctrl);
>
> free_irq(php_slot->irq, php_slot);
> php_slot->irq = 0;
> }
[Severity: High]
This is a pre-existing issue, but can the lockless check of php_slot->irq
lead to a double free?
If two threads execute pnv_php_disable_irq() concurrently (such as from
multiple sysfs writes on parent and child slots), could they both observe
php_slot->irq > 0 and attempt to call free_irq() for the same IRQ before
it is cleared?
[ ... ]
[Severity: High]
This is a pre-existing issue, but does pnv_php_alloc_slot() crash if
alloc_workqueue() fails?
drivers/pci/hotplug/pnv_php.c:pnv_php_alloc_slot() {
...
if (!php_slot->wq) {
SLOT_WARN(php_slot, "Cannot alloc workqueue\n");
...
}
If SLOT_WARN is invoked here, php_slot->bus is not yet initialized. The
SLOT_WARN macro evaluates to dev_warn(&(sl)->bus->dev, ...), which would take
the address of dev inside a NULL bus pointer. Could this trigger a kernel
Oops when dev_warn() attempts to read the device name?
[Severity: High]
This is a pre-existing issue, but is it safe to traverse bus->children and
bus->slots without acquiring pci_bus_sem?
drivers/pci/hotplug/pnv_php.c:pnv_php_disable_all_irqs() {
...
/* First go down child buses */
list_for_each_entry(child_bus, &bus->children, node)
pnv_php_disable_all_irqs(child_bus);
/* Disable IRQs for all pnv_php slots on this bus */
list_for_each_entry(slot, &bus->slots, list) {
...
}
Could a concurrent PCI bus rescan or device hot-unplug race with this
lockless traversal, leading to list corruption or a NULL pointer dereference?
[Severity: High]
This is a pre-existing issue, but is there a race condition when checking
php_slot->state locklessly?
drivers/pci/hotplug/pnv_php.c:pnv_php_enable() {
...
if (php_slot->state != PNV_PHP_STATE_REGISTERED)
return 0;
...
}
And in a concurrent path:
drivers/pci/hotplug/pnv_php.c:pnv_php_unregister_one() {
...
php_slot->state = PNV_PHP_STATE_OFFLINE;
pci_hp_deregister(&php_slot->slot);
...
}
If a concurrent driver unbind calls pnv_php_unregister_one(), it sets the
state to PNV_PHP_STATE_OFFLINE. If an asynchronous hotplug event executing
pnv_php_enable() has already passed the PNV_PHP_STATE_REGISTERED check,
could it erroneously operate on a slot that is being destroyed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260609084903.1352581-1-adityag@linux.ibm.com?part=1
prev parent reply other threads:[~2026-06-09 9:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 8:49 [PATCH v3] PCI: pnv_php: Add null checks for OpenCAPI PHBs Aditya Gupta
2026-06-09 9:05 ` sashiko-bot [this message]
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=20260609090549.B845F1F00899@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=adityag@linux.ibm.com \
--cc=linux-pci@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