From: sashiko-bot@kernel.org
To: "Yuwei Chen" <2522445001@qq.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: apple: Fix device node leak in apple_msi_init()
Date: Thu, 03 Dec 2026 04:37:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-247157@kernel.org> (raw)
In-Reply-To: <tencent_516AA3AC2858D46B6E2B25A966A39463BB09@qq.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] PCI: apple: premature of_node_put() before
irq_find_matching_fwspec()
--
commit fe1b42b4279ecaebe7033a6d4f50326cbfea38ed
Author: Yuwei Chen <2522445001@qq.com>
PCI: apple: Fix device node leak in apple_msi_init()
This commit adds of_node_put() calls in apple_msi_init() to drop the
device_node reference returned by of_parse_phandle_with_args() on the
error path and after populating pcie->fwspec.
> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
> index dfd0e345bc567..9a6d2e1e8eb42 100644
> --- a/drivers/pci/controller/pcie-apple.c
> +++ b/drivers/pci/controller/pcie-apple.c
> @@ -697,11 +697,14 @@ static int apple_msi_init(struct apple_pcie *pcie)
>
> ret = of_property_read_u32_index(to_of_node(fwnode), "msi-ranges",
> args.args_count + 1, &pcie->nvecs);
> - if (ret)
> + if (ret) {
> + of_node_put(args.np);
> return ret;
> + }
>
> of_phandle_args_to_fwspec(args.np, args.args, args.args_count,
> &pcie->fwspec);
> + of_node_put(args.np);
>
> pcie->bitmap = devm_bitmap_zalloc(pcie->dev, pcie->nvecs, GFP_KERNEL);
> if (!pcie->bitmap)
[Severity: Medium]
Does calling of_node_put(args.np) here leave pcie->fwspec.fwnode pointing
to an unpinned device_node before irq_find_matching_fwspec() uses it?
of_phandle_args_to_fwspec() only copies the fwnode pointer without taking
a reference, and no parent irq_domain is guaranteed to exist yet to pin
args.np.
After devm_bitmap_zalloc() sleeps, irq_find_matching_fwspec() passes
pcie->fwspec to registered domains' ops->select and ops->match callbacks
(such as msi_lib_irq_domain_select() -> fwnode_handle_get()), which
dereference fwnode->ops.
If a dynamic device tree node is detached and freed in that window,
irq_find_matching_fwspec() hits a use-after-free. Keeping args.np held
until after irq_find_matching_fwspec() returns (and dropping it on the
devm_bitmap_zalloc() error path) would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_516AA3AC2858D46B6E2B25A966A39463BB09@qq.com?part=1
prev parent reply other threads:[~2026-12-03 4:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 4:20 [PATCH] PCI: apple: Fix device node leak in apple_msi_init() Yuwei Chen
2026-12-03 4:37 ` 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=sashiko-outbox-247157@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=2522445001@qq.com \
--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