From: Herve Codina <herve.codina@bootlin.com>
To: sashiko-bot@kernel.org
Cc: sashiko@lists.linux.dev, linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 7/8] PCI: of: Set fwnode device of newly created PCI device nodes
Date: Wed, 13 May 2026 16:56:02 +0200 [thread overview]
Message-ID: <20260513165602.7d6f0f29@bootlin.com> (raw)
In-Reply-To: <20260512224622.973D1C2BCB8@smtp.kernel.org>
Hi All,
On Tue, 12 May 2026 22:46:21 +0000
sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] The patch fails to achieve its stated goal because `of_changeset_apply()` unconditionally sets the `FWNODE_FLAG_NOT_DEVICE` flag, causing `fw_devlink` to ignore the explicitly set fwnode device.
> - [High] Dangling `fwnode->dev` pointer leads to a Use-After-Free when the PCI device is removed.
> --
>
> commit 3981405050778ad9837921511772531243255e6a
> Author: Herve Codina <herve.codina@bootlin.com>
>
> PCI: of: Set fwnode device of newly created PCI device nodes
>
> This commit sets the fwnode device field of dynamically created PCI device
> nodes to the corresponding PCI device. This aims to allow fw_devlink to
> properly use the PCI device as a supplier, instead of falling back to the
> PCI root bridge.
>
> > diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> > index 7506208815a47..25fb02c3dc720 100644
> > --- a/drivers/pci/of.c
> > +++ b/drivers/pci/of.c
> > @@ -709,6 +709,13 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
> > if (ret)
> > goto out_free_node;
> >
> > + /*
> > + * Set the fwnode device in order to have fw_devlink creating links
> > + * pointing to this PCI device instead of walking up to the PCI host
> > + * bridge.
> > + */
> > + fw_devlink_set_device(&np->fwnode, &pdev->dev);
>
> Can this lead to a use-after-free regression when the PCI device is removed?
>
> During PCI device removal, of_pci_remove_node() calls
> device_remove_of_node(&pdev->dev) which explicitly sets pdev->dev.fwnode
> to NULL.
>
> Later, when device_del(&pdev->dev) is executed, its built-in fwnode cleanup
> mechanism is completely bypassed because pdev->dev.fwnode was already cleared:
>
> if (dev->fwnode && dev->fwnode->dev == dev)
> fw_devlink_set_device(dev->fwnode, NULL);
>
> This leaves np->fwnode.dev as a dangling pointer to &pdev->dev.
>
> If the OF node outlives the PCI device, any subsequent operation that accesses
> the node through fw_devlink will dereference the freed pdev->dev memory.
It will not. In device_remove_of_node(), the OF node is destroyed when the
of_changeset_revert() and of_changeset_destroy() are called.
>
> > +
> > ret = of_changeset_apply(cset);
>
> Does this code actually prevent fw_devlink from walking up to the PCI host
> bridge?
>
> of_changeset_apply() invokes __of_attach_node(), which unconditionally
> executes fwnode_set_flag(&np->fwnode, FWNODE_FLAG_NOT_DEVICE).
>
> When fw_devlink attempts to resolve a supplier, it checks for this flag:
>
> if (fwnode_test_flag(sup_handle, FWNODE_FLAG_NOT_DEVICE))
> sup_dev = fwnode_get_next_parent_dev(sup_handle);
>
> Because FWNODE_FLAG_NOT_DEVICE is set, fw_devlink bypasses the explicitly
> mapped np->fwnode.dev and walks up the tree to the parent device anyway.
>
> > if (ret)
> > goto out_free_node;
>
Well, an other series fixes this FWNODE_FLAG_NOT_DEVICE issue [1].
In this one, with or without the fw_devlink_set_device() call the issue is
present.
[1] patches 1 and 2 in https://lore.kernel.org/all/20260511155755.34428-1-herve.codina@bootlin.com/
Best regards,
Hervé
next prev parent reply other threads:[~2026-05-13 14:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 15:59 [PATCH v7 0/8] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-05-11 15:59 ` [PATCH v7 1/8] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-05-11 15:59 ` [PATCH v7 2/8] drivers: core: Use fw_devlink_set_device() Herve Codina
2026-05-11 15:59 ` [PATCH v7 3/8] pinctrl: cs42l43: " Herve Codina
2026-05-11 15:59 ` [PATCH v7 4/8] cxl/test: Use device_set_node() Herve Codina
2026-05-12 8:26 ` Andy Shevchenko
2026-05-11 15:59 ` [PATCH v7 5/8] cxl/test: Use fw_devlink_set_device() Herve Codina
2026-05-12 8:27 ` Andy Shevchenko
2026-05-11 15:59 ` [PATCH v7 6/8] PCI: of: " Herve Codina
2026-05-11 15:59 ` [PATCH v7 7/8] PCI: of: Set fwnode device of newly created PCI device nodes Herve Codina
2026-05-12 22:46 ` sashiko-bot
2026-05-13 14:56 ` Herve Codina [this message]
2026-05-11 15:59 ` [PATCH v7 8/8] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
2026-05-12 23:35 ` 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=20260513165602.7d6f0f29@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=sashiko@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