* [PATCH] PCI: apple: Fix device node leak in apple_msi_init()
@ 2026-12-03 4:20 Yuwei Chen
2026-12-03 4:37 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yuwei Chen @ 2026-12-03 4:20 UTC (permalink / raw)
To: Marc Zyngier; +Cc: Bjorn Helgaas, linux-pci
apple_msi_init() takes a reference on the parent interrupt controller
node with of_parse_phandle_with_args(). of_phandle_args_to_fwspec()
only copies the node pointer into pcie->fwspec, it does not take
another reference, and nothing in the driver drops the one returned by
the parse. That reference is also still held on the error return that
follows the "msi-ranges" parse.
Drop it once the fwspec has been filled, and on that earlier error
return.
Fixes: 476c41ed4597 ("PCI: apple: Implement MSI support")
Cc: stable@vger.kernel.org
Signed-off-by: Yuwei Chen <2522445001@qq.com>
---
drivers/pci/controller/pcie-apple.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index dfd0e345bc56..9a6d2e1e8eb4 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)
base-commit: 3dbdc13bd4b313b3d94c0f719378a4641a39db46
--
2.55.0.windows.3
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] PCI: apple: Fix device node leak in apple_msi_init()
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
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 4:37 UTC (permalink / raw)
To: Yuwei Chen; +Cc: linux-pci
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 4:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox