* [PATCH] PCI: meson: Fix potential use-after-free after PHY provider removal
@ 2026-11-18 14:28 Guangshuo Li
2026-11-18 14:43 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:28 UTC (permalink / raw)
To: Yue Wang, Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl
Cc: linux-pci, linux-amlogic, linux-arm-kernel, linux-kernel
The PHY reference keeps the PHY device alive, but not the provider
driver resources used by its callbacks. Without a managed dependency,
unbinding the provider first can leave meson_pcie_power_off() accessing
freed provider data during PCIe removal.
Add a managed link to the PHY provider so the PCIe controller is unbound
before the provider releases its resources.
This issue was found by our static analysis tool under development.
Fixes: 4b0dc84b2939 ("PCI: meson: Add missing remove callback")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/pci/controller/dwc/pci-meson.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
index 8559d132dcde..251673bc5963 100644
--- a/drivers/pci/controller/dwc/pci-meson.c
+++ b/drivers/pci/controller/dwc/pci-meson.c
@@ -401,6 +401,10 @@ static int meson_pcie_probe(struct platform_device *pdev)
return PTR_ERR(mp->phy);
}
+ if (!device_link_add(dev, mp->phy->dev.parent,
+ DL_FLAG_AUTOREMOVE_CONSUMER))
+ return dev_err_probe(dev, -EINVAL, "failed to link PHY provider\n");
+
mp->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(mp->reset_gpio)) {
dev_err(dev, "get reset gpio failed\n");
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] PCI: meson: Fix potential use-after-free after PHY provider removal
2026-11-18 14:28 [PATCH] PCI: meson: Fix potential use-after-free after PHY provider removal Guangshuo Li
@ 2026-11-18 14:43 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18 14:43 UTC (permalink / raw)
To: Guangshuo Li; +Cc: linux-pci, linux-amlogic, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] PCI: meson: open-coded device_link_add() on mp->phy->dev.parent
in meson_pcie_probe()
--
commit c65612b1d0d3578038649d0fdc61a7521f33e1fc
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
PCI: meson: Fix potential use-after-free after PHY provider removal
This commit adds a managed device link from the Meson PCIe device to its
PHY provider in meson_pcie_probe() so the PCIe controller is unbound
before the PHY provider releases its resources.
> diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
> index 8559d132dcde8..251673bc5963c 100644
> --- a/drivers/pci/controller/dwc/pci-meson.c
> +++ b/drivers/pci/controller/dwc/pci-meson.c
> @@ -401,6 +401,10 @@ static int meson_pcie_probe(struct platform_device *pdev)
> return PTR_ERR(mp->phy);
> }
>
> + if (!device_link_add(dev, mp->phy->dev.parent,
> + DL_FLAG_AUTOREMOVE_CONSUMER))
> + return dev_err_probe(dev, -EINVAL, "failed to link PHY provider\n");
[Severity: Low]
Should a PHY consumer driver reach into mp->phy->dev.parent to call
device_link_add() directly?
On Device Tree platforms, fw_devlink already parses the "phys" property
in drivers/of/property.c (parse_phys()) and creates a managed device
link between dev and the PHY provider, which causes
__device_release_driver() to unbind meson-pcie before the PHY provider
releases its devres resources; device_link_add() here just finds that
existing link and returns it without adding DL_FLAG_AUTOREMOVE_CONSUMER.
Reaching into struct phy internals also bypasses struct phy
encapsulation, and any provider device link needed when fw_devlink is
disabled belongs in the PHY core (phy_get() in drivers/phy/phy-core.c)
rather than in individual consumer drivers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-324f82bd41-pci-meson-0@mail.sdu.edu.cn?part=1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 14:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 14:28 [PATCH] PCI: meson: Fix potential use-after-free after PHY provider removal Guangshuo Li
2026-11-18 14:43 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox