From: Richard Cheng <icheng@nvidia.com>
To: Herve Codina <herve.codina@bootlin.com>
Cc: Andrew Lunn <andrew@lunn.ch>, Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
David Rhodes <david.rhodes@cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Linus Walleij <linusw@kernel.org>, Len Brown <lenb@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jic23@kernel.org>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dan Williams <djbw@kernel.org>, Ira Weiny <iweiny@kernel.org>,
Li Ming <ming.li@zohomail.com>, Lizhi Hou <lizhi.hou@amd.com>,
driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, linux-sound@vger.kernel.org,
patches@opensource.cirrus.com, linux-gpio@vger.kernel.org,
linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org,
Allan Nielsen <allan.nielsen@microchip.com>,
Horatiu Vultur <horatiu.vultur@microchip.com>,
Daniel Machon <daniel.machon@microchip.com>,
Steen Hegelund <steen.hegelund@microchip.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
stable+noautosel@kernel.org
Subject: Re: [PATCH v10 10/10] PCI: of: Guard against node removal with incorrect np->data
Date: Tue, 21 Jul 2026 15:33:21 +0800 [thread overview]
Message-ID: <al8faCx6ydg7BI9h@MWDK4CY14F> (raw)
In-Reply-To: <20260717145147.823749-11-herve.codina@bootlin.com>
On Fri, Jul 17, 2026 at 04:51:45PM +0800, Herve Codina wrote:
> of_pci_remove_node() and of_pci_remove_host_bridge_node() check
> whether the node is dynamic but not whether it has valid private data.
>
> During the node creation, an OF changeset is used and this changeset is
> stored in np->data to be available for removal functions.
>
> If, for instance, a PCI host bridge is created using a device-tree
> overlay, the related node will have the dynamic flag set but np->data
> will be NULL. This leads to NULL pointer dereferences.
>
> Further more, having a NULL np->data pointer means that the node has
> been created out of our PCI node creation process and so shouldn't be
> handled by our PCI node removal process.
>
> Add a np->data check for NULL to bail out early of PCI node removal
> functions.
>
> Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
> Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node")
> Cc: <stable+noautosel@kernel.org> # Not triggered but 'This could be a problem...'
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
> drivers/pci/of.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 28896f748e8d..9f35e1e07cdc 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;
>
Hi Herve,
I wonder whether "np->data != NULL" is sufficient to identify nodes
created by these PCI helpers.
struct device_node::data is a generic pointer. As my limited knowledge,
on pSeries, pci_dn_reconfig_notifier() handles OF_RECONFIG_ATTACH_NODE
and calls pci_add_device_node_info(), which stores a "struct pci_dn *"
in "dn->data"
Coud an OF_DYNAMIC PCI node from that path later reach of_pci_remove_node()
or of_pci_remove_host_bridge_node() ?
If so, the new guard would accpet the non-NULL np->data, and the removal path
would pass a "struct pci_dn *" to of_changeset_revert() and of_changeset_destroy()
as though it were the PCI-create "struct of_changeset *" ?
I have only reviewed this statically, didn't do a real pSeries setup to test it,
so I may be missing something. Could you confirm whether this scenario is possible?
If so, it seems that a stronger ownership indicator would be needed.
Best regards,
Richard Cheng.
> fw_devlink_set_device(&np->fwnode, NULL);
> @@ -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);
> --
> 2.55.0
>
next prev parent reply other threads:[~2026-07-21 7:33 UTC|newest]
Thread overview: 9+ 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:51 ` [PATCH v10 04/10] cxl/test: Use device_set_node() Herve Codina
2026-07-17 14:51 ` [PATCH v10 06/10] PCI: of: Use fw_devlink_set_device() Herve Codina
2026-07-17 14:51 ` [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Herve Codina
2026-07-17 14:51 ` [PATCH v10 08/10] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
2026-07-17 14:51 ` [PATCH v10 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
[not found] ` <20260717145147.823749-11-herve.codina@bootlin.com>
2026-07-21 7:33 ` Richard Cheng [this message]
2026-07-21 8:12 ` [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Richard Cheng
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=al8faCx6ydg7BI9h@MWDK4CY14F \
--to=icheng@nvidia.com \
--cc=alison.schofield@intel.com \
--cc=allan.nielsen@microchip.com \
--cc=andrew@lunn.ch \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=ckeepax@opensource.cirrus.com \
--cc=dakr@kernel.org \
--cc=daniel.machon@microchip.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=david.rhodes@cirrus.com \
--cc=djbw@kernel.org \
--cc=djrscally@gmail.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=herve.codina@bootlin.com \
--cc=horatiu.vultur@microchip.com \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=lenb@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=luca.ceresoli@bootlin.com \
--cc=ming.li@zohomail.com \
--cc=patches@opensource.cirrus.com \
--cc=rafael@kernel.org \
--cc=rf@opensource.cirrus.com \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=saravanak@kernel.org \
--cc=stable+noautosel@kernel.org \
--cc=steen.hegelund@microchip.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vishal.l.verma@intel.com \
/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