Skip to contentSkip to conversation

PCI: imx6: Avoid dereferencing a NULL clock name

PATCH Superseded Rudi Heitbaum 4 participants 4 messages Aug 2 – Sep 10

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: imx6: Avoid dereferencing a NULL clock name

of_clk_bulk_get() leaves clk_bulk_data::id as NULL for every clock that has no matching entry in "clock-names", which is legal: a node may list more "clocks" phandles than it names. The extref scan dereferences that id unconditionally, so such a node oopses during probe.

Check clk_bulk_data::id before dereferencing it.

Fixes d8574ce57d76 ("PCI: imx6: Add external reference clock input mode support")
---
 drivers/pci/controller/dwc/pci-imx6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-imx6.c +2 -1
index f7389b5437df..dcdeba1856f7 100644
@@ -1831,7 +1831,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, imx_pcie->num_clks,
 				     "failed to get clocks\n");
 	for (i = 0; i < imx_pcie->num_clks; i++)
-		if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
+		if (imx_pcie->clks[i].id &&
+		    strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
 			imx_pcie->enable_ext_refclk = true;
 
 	if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHYDRV)) {
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch successfully fixes a NULL pointer dereference in imx_pcie_probe() by checking imx_pcie->clks[i].id before passing it to strncmp(), but it misses an identical preexisting vulnerability in imx_setup_phy_mpll(). --

--- Patch [1]: [PATCH] PCI: imx6: Avoid dereferencing a NULL clock name --- commit 59f2384c27b018977b395ad505a6ac37e2ecf39a
Author: Rudi Heitbaum <[email protected]>

PCI: imx6: Avoid dereferencing a NULL clock name

This patch fixes a kernel oops in imx_pcie_probe() by checking if clk_bulk_data::id is NULL before passing it to strncmp(). This happens because of_clk_bulk_get() legally leaves the id as NULL for unnamed clocks.

Quoted 5 lines
drivers/pci/controller/dwc/pci-imx6.c +0 -0
index 98e1db751132a..9a9efc2ab894a 100644

drivers/pci/controller/dwc/pci-imx6.c static int imx_pcie_probe(struct platform_device *pdev) · line 1833

Quoted 9 lines
drivers/pci/controller/dwc/pci-imx6.c +2 -1
@@ -1826,7 +1826,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, imx_pcie->num_clks,
 				     "failed to get clocks\n");
 	for (i = 0; i < imx_pcie->num_clks; i++)
-		if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
+		if (imx_pcie->clks[i].id &&
+		    strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
 			imx_pcie->enable_ext_refclk = true;
 
 	if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHYDRV)) {

[Severity: High]
This is a pre-existing issue, but this same vulnerability appears to exist elsewhere in this driver.

In imx_setup_phy_mpll(), the driver iterates over the clocks and calls strncmp() on the id without checking if it is NULL:

drivers/pci/controller/dwc/pci-imx6.c:imx_setup_phy_mpll() {
    ...
	for (i = 0; i < imx_pcie->num_clks; i++)
		if (strncmp(clks[i].id, "pcie_phy", 8) == 0)
			phy_rate = clk_get_rate(clks[i].clk);
    ...
}

Could this cause a similar oops during probe when IMX_PCIE_FLAG_IMX_PHY is used and an unnamed clock is present? Would it make sense to apply the same NULL check to this loop?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/am8iBwJSEhYhWTqk@6cfee64030a6?part=1
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Rudi Heitbaum
Quoted 20 lines

-----Original Message-----
From: Rudi Heitbaum <[email protected]>
Sent: Sunday, August 2, 2026 6:55 PM
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>
Cc: Lorenzo Pieralisi <[email protected]>; Krzysztof Wilczyński <[email protected]>; Manivannan Sadhasivam <[email protected]>; Rob Herring <[email protected]>; Bjorn Helgaas <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH] PCI: imx6: Avoid dereferencing a NULL clock name

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

of_clk_bulk_get() leaves clk_bulk_data::id as NULL for every clock that has no matching entry in "clock-names", which is legal: a node may list more "clocks" phandles than it names. The extref scan dereferences that id unconditionally, so such a node oopses during probe.

Quoted 6 lines

Check clk_bulk_data::id before dereferencing it.

Fixes d8574ce57d76 ("PCI: imx6: Add external reference clock input mode

support")

Good catch.
This isn't triggered in my daily tests, but the fix is correct. Thanks for this fix.

Best Regards
Richard Zhu

Quoted 22 lines
---
 drivers/pci/controller/dwc/pci-imx6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-imx6.c +2 -1
index f7389b5437df..dcdeba1856f7 100644
@@ -1831,7 +1831,8 @@ static int imx_pcie_probe(struct platform_device
 *pdev)
                return dev_err_probe(dev, imx_pcie->num_clks,
                                     "failed to get clocks\n");
        for (i = 0; i < imx_pcie->num_clks; i++)
-               if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
+               if (imx_pcie->clks[i].id &&
+                   strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
                        imx_pcie->enable_ext_refclk = true;
 
        if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHYDRV)) {

--
2.53.0

#3 lore raw
In reply to Rudi Heitbaum
Quoted 19 lines · Rudi Heitbaum

of_clk_bulk_get() leaves clk_bulk_data::id as NULL for every clock that has no matching entry in "clock-names", which is legal: a node may list more "clocks" phandles than it names. The extref scan dereferences that id unconditionally, so such a node oopses during probe.

Check clk_bulk_data::id before dereferencing it.

Fixes d8574ce57d76 ("PCI: imx6: Add external reference clock input mode support")
---
 drivers/pci/controller/dwc/pci-imx6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-imx6.c +0 -0
index f7389b5437df..dcdeba1856f7 100644

drivers/pci/controller/dwc/pci-imx6.c static int imx_pcie_probe(struct platform_device *pdev) · line 1835

Quoted 6 lines
drivers/pci/controller/dwc/pci-imx6.c +2 -1
@@ -1831,7 +1831,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, imx_pcie->num_clks,
 				     "failed to get clocks\n");
 	for (i = 0; i < imx_pcie->num_clks; i++)
-		if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
+		if (imx_pcie->clks[i].id &&
+		    strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)

As Sashiko mentioned, there are other places in this driver without the check. Please fix all of them in a single patch.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்