From: sashiko-bot@kernel.org
To: "Herve Codina" <herve.codina@bootlin.com>
Cc: linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset
Date: Wed, 09 Sep 2026 08:17:54 +0000 [thread overview]
Message-ID: <20260909081755.444E91F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909080114.591938-11-herve.codina@bootlin.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing NULL check on `np` in `of_pci_remove_node` and `of_pci_remove_host_bridge_node` leading to kernel panic.
- [High] Dangling pointer in `pdev->cset` and `bridge->cset` after freeing, leading to potential use-after-free or double-free.
--
commit 506858ef76ab83f59a005bd51f3fde0f4d73a6a2
Author: Herve Codina <herve.codina@bootlin.com>
PCI: of: Avoid np->data usage for the node changeset
This patch modifies how OF changeset references are stored during PCI node
creation. Instead of using np->data, which can be altered by platform code,
it stores the changeset in pdev->cset or bridge->cset. This ensures the
correct changeset is reverted and destroyed during node removal.
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 0a5797652e183..cd87128c71ddc 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -732,15 +732,16 @@ void of_pci_remove_node(struct pci_dev *pdev)
> {
> struct device_node *np;
>
> - np = pci_device_to_OF_node(pdev);
> - if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> + if (!pdev->cset)
> return;
>
> + np = pci_device_to_OF_node(pdev);
> fw_devlink_set_device(&np->fwnode, NULL);
[Severity: High]
Will this result in an invalid pointer dereference if np is NULL?
The previous implementation had a NULL check for np, but the new code computes
&np->fwnode unconditionally. If pdev->dev.of_node is cleared prior to removal,
pci_device_to_OF_node() will return NULL, causing fw_devlink_set_device() to
dereference an offset address.
> device_remove_of_node(&pdev->dev);
> - of_changeset_revert(np->data);
> - of_changeset_destroy(np->data);
> + of_changeset_revert(pdev->cset);
> + of_changeset_destroy(pdev->cset);
> of_node_put(np);
> + kfree(pdev->cset);
[Severity: High]
Is it possible for of_pci_remove_node() to be called twice for the same device?
If so, leaving pdev->cset as a dangling pointer could lead to a double-free.
Should pdev->cset be set to NULL after kfree() so that the earlier
if (!pdev->cset) check can prevent a second execution?
[ ... ]
> @@ -828,16 +828,17 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge)
> {
> struct device_node *np;
>
> - np = pci_bus_to_OF_node(bridge->bus);
> - if (!np || !of_node_check_flag(np, OF_DYNAMIC))
> + if (!bridge->cset)
> return;
>
> + np = pci_bus_to_OF_node(bridge->bus);
> fw_devlink_set_device(&np->fwnode, NULL);
[Severity: High]
Can np evaluate to NULL here?
Similar to the issue in of_pci_remove_node(), if pci_bus_to_OF_node() returns
NULL, the missing NULL check will cause a crash during the &np->fwnode pointer
arithmetic.
> device_remove_of_node(&bridge->bus->dev);
> device_remove_of_node(&bridge->dev);
> - of_changeset_revert(np->data);
> - of_changeset_destroy(np->data);
> + of_changeset_revert(bridge->cset);
> + of_changeset_destroy(bridge->cset);
> of_node_put(np);
> + kfree(bridge->cset);
[Severity: High]
Could this lead to a use-after-free or double-free on bridge->cset?
If a removal API like pci_stop_root_bus() is invoked multiple times, the
dangling pointer bypasses the if (!bridge->cset) check at the start of the
function, resulting in a double-free on the changeset.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260909080114.591938-1-herve.codina@bootlin.com?part=10
next prev parent reply other threads:[~2026-09-09 8:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 8:00 [PATCH v11 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-09-09 8:01 ` [PATCH v11 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-09-09 8:05 ` sashiko-bot
2026-09-09 11:31 ` Bartosz Golaszewski
2026-09-09 8:01 ` [PATCH v11 02/10] drivers: core: Use fw_devlink_set_device() Herve Codina
2026-09-09 8:11 ` sashiko-bot
2026-09-09 9:05 ` Bartosz Golaszewski
2026-09-09 8:01 ` [PATCH v11 03/10] pinctrl: cs42l43: " Herve Codina
2026-09-09 8:05 ` sashiko-bot
2026-09-09 9:06 ` Bartosz Golaszewski
2026-09-09 8:01 ` [PATCH v11 04/10] cxl/test: Use device_set_node() Herve Codina
2026-09-09 8:04 ` sashiko-bot
2026-09-09 9:06 ` Bartosz Golaszewski
2026-09-09 8:01 ` [PATCH v11 05/10] cxl/test: Use fw_devlink_set_device() Herve Codina
2026-09-09 8:04 ` sashiko-bot
2026-09-09 9:06 ` Bartosz Golaszewski
2026-09-09 9:23 ` Bartosz Golaszewski
2026-09-09 11:27 ` Bartosz Golaszewski
2026-09-09 8:01 ` [PATCH v11 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
2026-09-09 8:12 ` sashiko-bot
2026-09-09 11:31 ` Bartosz Golaszewski
2026-09-09 8:01 ` [PATCH v11 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
2026-09-09 8:14 ` sashiko-bot
2026-09-09 8:01 ` [PATCH v11 10/10] PCI: of: Avoid np->data usage for the node changeset Herve Codina
2026-09-09 8:17 ` sashiko-bot [this message]
2026-09-09 9:06 ` Herve Codina
2026-09-09 9:12 ` Herve Codina
[not found] ` <20260909080114.591938-10-herve.codina@bootlin.com>
2026-09-09 8:15 ` [PATCH v11 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node sashiko-bot
[not found] ` <20260909080114.591938-7-herve.codina@bootlin.com>
2026-09-09 8:13 ` [PATCH v11 06/10] PCI: of: Use fw_devlink_set_device() sashiko-bot
2026-09-09 11:27 ` Bartosz Golaszewski
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=20260909081755.444E91F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=herve.codina@bootlin.com \
--cc=linux-cxl@vger.kernel.org \
--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