Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] phy: berlin-sata: count available child nodes
@ 2026-11-19  8:15 Wang Haoran
  2026-11-19  8:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Haoran @ 2026-11-19  8:15 UTC (permalink / raw)
  To: vkoul; +Cc: neil.armstrong, mani, linux-phy, linux-kernel, wanghr2026

phy_berlin_sata_probe() sizes priv->nphys with of_get_child_count(), which
counts every child, but fills priv->phys[] only from available children. A
disabled child therefore leaves trailing NULL entries, and
phy_berlin_sata_phy_xlate() dereferences priv->phys[i]->index for them. A
device tree that disables a PHY but still points a consumer at it crashes
with a NULL dereference in the generic ahci_platform path during probe.

Count available children instead.

Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: 942a31b52191 ("phy: add a driver for the Berlin SATA PHY")
---

diff --git a/drivers/phy/marvell/phy-berlin-sata.c b/drivers/phy/marvell/phy-berlin-sata.c
index 084671ee7d56..6ed9c8e2b6f4 100644
--- a/drivers/phy/marvell/phy-berlin-sata.c
+++ b/drivers/phy/marvell/phy-berlin-sata.c
@@ -212,7 +212,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->clk))
 		return PTR_ERR(priv->clk);
 
-	priv->nphys = of_get_child_count(dev->of_node);
+	priv->nphys = of_get_available_child_count(dev->of_node);
 	if (priv->nphys == 0)
 		return -ENODEV;
 

---

PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):

Device tree injection, spliced into the QEMU virt machine DT:

    osc25m: clock-25m { compatible = "fixed-clock"; #clock-cells = <0>;
        clock-frequency = <25000000>; };

    reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;
        phy-regs@7f100000 { no-map; reg = <0x0 0x7f100000 0x0 0x1000>; };
        ahci-regs@7f110000 { no-map; reg = <0x0 0x7f110000 0x0 0x1000>; }; };

    sata_phy: sata-phy@7f100000 { compatible = "marvell,berlin2q-sata-phy";
        reg = <0x0 0x7f100000 0x0 0x1000>; clocks = <&osc25m>;
        #phy-cells = <1>;
        phy@0 { reg = <0>; };
        phy@1 { reg = <1>; status = "disabled"; }; };

    sata@7f110000 { compatible = "generic-ahci"; reg = <0x0 0x7f110000 0x0 0x1000>;
        interrupt-parent = <&gpio0>; interrupts = <5 8>; phys = <&sata_phy 1>; };

phy@1 is disabled but the generic-ahci consumer still points at it via
phys = <&sata_phy 1>, so xlate() walks a NULL slot.

Trigger:

    modprobe phy-berlin-sata
    modprobe ahci_platform

Result:

    Unable to handle kernel NULL pointer dereference at virtual address 000000000000000c
    pc : phy_berlin_sata_phy_xlate+0x30/0x60 [phy_berlin_sata]
    Call trace: ahci_platform_get_phy then ahci_probe

Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. The device tree is trusted input (a bad DT
requires root or physical access), so this is not a security fix, but it
prevents a potential resource leak or system failure on a failed probe or
an old or malformed DT.


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19  8:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  8:15 [PATCH] phy: berlin-sata: count available child nodes Wang Haoran
2026-11-19  8:23 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox