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 v9 6/9] PCI: of: Use fw_devlink_set_device()
Date: Wed, 08 Jul 2026 10:29:21 +0000 [thread overview]
Message-ID: <20260708102921.BDBD31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708100302.517792-7-herve.codina@bootlin.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Dangling pointer in `np->fwnode.dev` on error paths and during bridge removal, leading to a potential use-after-free.
--
--- Patch [6]: [PATCH v9 6/9] PCI: of: Use fw_devlink_set_device() ---
commit e05d94ee3b1f4fa9d5ff1b29db6b40e43eca7313
Author: Herve Codina <herve.codina@bootlin.com>
PCI: of: Use fw_devlink_set_device()
The code directly set the fwnode.dev field. This commit updates the code
to use the dedicated fw_devlink_set_device() helper to perform this
operation.
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 8b18c4ba845cf..ee9eb384b377a 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -803,7 +803,7 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)
> * bus. Avoid any new device creation.
> */
> of_node_set_flag(np, OF_POPULATED);
> - np->fwnode.dev = &bridge->dev;
> + fw_devlink_set_device(&np->fwnode, &bridge->dev);
[Severity: High]
This isn't a bug introduced by this patch, but could this lead to a
use-after-free on error paths?
In of_pci_make_host_bridge_node(), if an error occurs after setting up the
fwnode (such as of_changeset_apply() or device_add_of_node() failing), the
error path removes the node from the tree and releases its reference, but
fails to clear the np->fwnode.dev pointer:
out_revert_cset:
np->data = NULL;
of_changeset_revert(cset);
out_free_node:
of_node_put(np);
Because device_remove_of_node() only clears the forward pointer
(dev->fwnode) and not the backpointer, np->fwnode.dev remains dangling. If
another thread holds a reference to np, the node outlives the function.
When the bridge is later freed, any concurrent access via
get_dev_from_fwnode(&np->fwnode) could dereference freed memory.
The same dangling pointer issue appears to exist in
of_pci_remove_host_bridge_node() during teardown:
void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge)
{
...
device_remove_of_node(&bridge->bus->dev);
device_remove_of_node(&bridge->dev);
of_changeset_revert(np->data);
of_changeset_destroy(np->data);
of_node_put(np);
}
> fwnode_dev_initialized(&np->fwnode, true);
>
> ret = of_changeset_apply(cset);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708100302.517792-1-herve.codina@bootlin.com?part=6
next prev parent reply other threads:[~2026-07-08 10:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 10:02 [PATCH v9 0/9] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-07-08 10:02 ` [PATCH v9 1/9] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-07-08 10:08 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 2/9] drivers: core: Use fw_devlink_set_device() Herve Codina
2026-07-08 10:12 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 3/9] pinctrl: cs42l43: " Herve Codina
2026-07-08 10:20 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 4/9] cxl/test: Use device_set_node() Herve Codina
2026-07-08 10:15 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 5/9] cxl/test: Use fw_devlink_set_device() Herve Codina
2026-07-08 10:16 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 6/9] PCI: of: " Herve Codina
2026-07-08 10:29 ` sashiko-bot [this message]
2026-07-08 10:02 ` [PATCH v9 7/9] PCI: of: Clear fwnode->dev during root bridge node removal Herve Codina
2026-07-08 10:34 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 8/9] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
2026-07-08 10:43 ` sashiko-bot
2026-07-08 10:02 ` [PATCH v9 9/9] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
2026-07-08 10:48 ` sashiko-bot
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=20260708102921.BDBD31F000E9@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