From: sashiko-bot@kernel.org
To: "Herve Codina" <herve.codina@bootlin.com>
Cc: linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org
Subject: Re: [PATCH v10 10/10] PCI: of: Guard against node removal with incorrect np->data
Date: Fri, 17 Jul 2026 15:19:23 +0000 [thread overview]
Message-ID: <20260717151924.38C991F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717145147.823749-11-herve.codina@bootlin.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unsafe cast of `np->data` to `struct of_changeset *` without type validation, leading to type confusion and potential memory corruption.
--
--- Patch [10]: [PATCH v10 10/10] PCI: of: Guard against node removal with incorrect np->data ---
commit 3c2e9ae91c2c8b16b99779200dfab12179834af1
Author: Herve Codina <herve.codina@bootlin.com>
PCI: of: Guard against node removal with incorrect np->data
This commit adds a check for !np->data in of_pci_remove_node() and
of_pci_remove_host_bridge_node() to prevent NULL pointer dereferences. It
protects against dynamic nodes created by device-tree overlays that do not
populate np->data.
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 28896f748e8d3..9f35e1e07cdcd 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -654,7 +654,7 @@ 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 (!np || !of_node_check_flag(np, OF_DYNAMIC) || !np->data)
> return;
>
> fw_devlink_set_device(&np->fwnode, NULL);
[Severity: High]
This isn't a bug introduced by this patch, but does this still leave a type
confusion issue if np->data is populated by another subsystem?
While this patch prevents a NULL pointer dereference, it doesn't verify that a
non-NULL np->data actually points to a struct of_changeset. On some platforms
like PowerPC, the OF_RECONFIG_ATTACH_NODE notifier (e.g., in
pci_dn_reconfig_notifier()) intercepts node additions and populates np->data
with its own structure, such as a struct pci_dn.
If that happens, and the device is later removed, of_pci_remove_node() will
see a non-NULL np->data, proceed past this check, and pass the foreign pointer
to of_changeset_revert() and of_changeset_destroy() lower down in the function:
fw_devlink_set_device(&np->fwnode, NULL);
device_remove_of_node(&pdev->dev);
of_changeset_revert(np->data);
of_changeset_destroy(np->data);
Could this result in memory corruption or a kernel panic when the wrong type
is cast and dereferenced?
[ ... ]
> @@ -750,7 +750,7 @@ 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 (!np || !of_node_check_flag(np, OF_DYNAMIC) || !np->data)
> return;
>
> fw_devlink_set_device(&np->fwnode, NULL);
[Severity: High]
This isn't a bug introduced by this patch, but the same type confusion issue
seems to apply here in of_pci_remove_host_bridge_node().
If the host bridge node's np->data is populated by another subsystem with a
different structure, will passing it to of_changeset_revert() and
of_changeset_destroy() cause memory corruption?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260717145147.823749-1-herve.codina@bootlin.com?part=10
prev parent reply other threads:[~2026-07-17 15:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-07-17 14:51 ` [PATCH v10 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-07-17 14:58 ` sashiko-bot
2026-07-17 14:51 ` [PATCH v10 03/10] pinctrl: cs42l43: Use fw_devlink_set_device() Herve Codina
2026-07-17 15:05 ` sashiko-bot
2026-07-17 14:51 ` [PATCH v10 05/10] cxl/test: " Herve Codina
2026-07-17 14:58 ` sashiko-bot
2026-07-17 14:51 ` [PATCH v10 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
2026-07-17 17:08 ` sashiko-bot
[not found] ` <20260717145147.823749-5-herve.codina@bootlin.com>
2026-07-17 14:59 ` [PATCH v10 04/10] cxl/test: Use device_set_node() sashiko-bot
[not found] ` <20260717145147.823749-7-herve.codina@bootlin.com>
2026-07-17 15:03 ` [PATCH v10 06/10] PCI: of: Use fw_devlink_set_device() sashiko-bot
[not found] ` <20260717145147.823749-8-herve.codina@bootlin.com>
2026-07-17 15:06 ` [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path sashiko-bot
[not found] ` <20260717145147.823749-9-herve.codina@bootlin.com>
2026-07-17 15:10 ` [PATCH v10 08/10] PCI: of: Set fwnode device of newly created PCI device nodes sashiko-bot
[not found] ` <20260717145147.823749-3-herve.codina@bootlin.com>
2026-07-17 15:12 ` [PATCH v10 02/10] drivers: core: Use fw_devlink_set_device() sashiko-bot
[not found] ` <20260717145147.823749-11-herve.codina@bootlin.com>
2026-07-17 15:19 ` 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=20260717151924.38C991F000E9@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