Skip to contentSkip to conversation

phy: qcom: qmp-usb: fix NULL-deref on runtime suspend

PATCH Applied Johan Hovold 4 participants 9 messages Sep 11, 2024 – Oct 17, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover phy: qcom: qmp-usb: fix NULL-deref on runtime suspend

When working on suspend support for Qualcomm platforms like x1e80100, I ran into a NULL-pointer dereference in one of the QMP drivers. Turns out this issue has since been reproduced in two more drivers.

Johan

Johan Hovold (4):
phy: qcom: qmp-usb: fix NULL-deref on runtime suspend
phy: qcom: qmp-usb-legacy: fix NULL-deref on runtime suspend
phy: qcom: qmp-usbc: fix NULL-deref on runtime suspend
phy: qcom: qmp-usb: move driver data initialisation earlier

 drivers/phy/qualcomm/phy-qcom-qmp-combo.c      | 3 +--
 drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c | 1 +
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c        | 1 +
 drivers/phy/qualcomm/phy-qcom-qmp-usbc.c       | 1 +
 4 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.44.2
#1 lore raw

PATCH 1/4 phy: qcom: qmp-usb: fix NULL-deref on runtime suspend

Commit 413db06c05e7 ("phy: qcom-qmp-usb: clean up probe initialisation") removed most users of the platform device driver data, but mistakenly also removed the initialisation despite the data still being used in the runtime PM callbacks.

Restore the driver data initialisation at probe to avoid a NULL-pointer dereference on runtime suspend.

Apparently no one uses runtime PM, which currently needs to be enabled manually through sysfs, with this driver.

Fixes 413db06c05e7 ("phy: qcom-qmp-usb: clean up probe initialisation")
---
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
index 49f4a53f9b2c..76068393e4ba 100644
@@ -2191,6 +2191,7 @@ static int qmp_usb_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	qmp->dev = dev;
+	dev_set_drvdata(dev, qmp);
 
 	qmp->cfg = of_device_get_match_data(dev);
 	if (!qmp->cfg)
Signature · 1 line
2.44.2
#2 lore raw

PATCH 2/4 phy: qcom: qmp-usb-legacy: fix NULL-deref on runtime suspend

In reply to Johan Hovold

Commit 413db06c05e7 ("phy: qcom-qmp-usb: clean up probe initialisation") removed most users of the platform device driver data from the qcom-qmp-usb driver, but mistakenly also removed the initialisation despite the data still being used in the runtime PM callbacks. This bug was later reproduced when the driver was copied to create the qmp-usb-legacy driver.

Restore the driver data initialisation at probe to avoid a NULL-pointer dereference on runtime suspend.

Apparently no one uses runtime PM, which currently needs to be enabled manually through sysfs, with these drivers.

Fixes e464a3180a43 ("phy: qcom-qmp-usb: split off the legacy USB+dp_com support")
---
 drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c | 1 +
 1 file changed, 1 insertion(+)
drivers/phy/qualcomm/phy-qcom-qmp-usb-legacy.c +1 -0
index 6d0ba39c1943..8bf951b0490c 100644
@@ -1248,6 +1248,7 @@ static int qmp_usb_legacy_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	qmp->dev = dev;
+	dev_set_drvdata(dev, qmp);
 
 	qmp->cfg = of_device_get_match_data(dev);
 	if (!qmp->cfg)
Signature · 1 line
2.44.2
#3 lore raw

PATCH 3/4 phy: qcom: qmp-usbc: fix NULL-deref on runtime suspend

In reply to Johan Hovold

Commit 413db06c05e7 ("phy: qcom-qmp-usb: clean up probe initialisation") removed most users of the platform device driver data from the qcom-qmp-usb driver, but mistakenly also removed the initialisation despite the data still being used in the runtime PM callbacks. This bug was later reproduced when the driver was copied to create the qmp-usbc driver.

Restore the driver data initialisation at probe to avoid a NULL-pointer dereference on runtime suspend.

Apparently no one uses runtime PM, which currently needs to be enabled manually through sysfs, with these drivers.

Fixes 19281571a4d5 ("phy: qcom: qmp-usb: split USB-C PHY driver")
---
 drivers/phy/qualcomm/phy-qcom-qmp-usbc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/phy/qualcomm/phy-qcom-qmp-usbc.c +1 -0
index 5cbc5fd529eb..dea3456f88b1 100644
@@ -1049,6 +1049,7 @@ static int qmp_usbc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	qmp->dev = dev;
+	dev_set_drvdata(dev, qmp);
 
 	qmp->orientation = TYPEC_ORIENTATION_NORMAL;
 
Signature · 1 line
2.44.2
#4 lore raw

PATCH 4/4 phy: qcom: qmp-usb: move driver data initialisation earlier

In reply to Johan Hovold

Commit 44aff8e31080 ("phy: qcom-qmp-combo: clean up probe initialisation") removed most users of the platform device driver data, but mistakenly also removed the initialisation despite the data still being used in the runtime PM callbacks.

The initialisation was soon after restored by commit 83a0bbe39b17 ("phy:
qcom-qmp-combo: add support for updated sc8280xp binding") but now happens slightly later during probe. This should not cause any trouble currently as runtime PM needs to be enabled manually through sysfs and the platform device would not be suspended before the PHY has been registered anyway.

Move the driver data initialisation to avoid a NULL-pointer dereference on runtime suspend if runtime PM is ever enabled by default in this driver.

Fixes 44aff8e31080 ("phy: qcom-qmp-combo: clean up probe initialisation")
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +1 -2
index c478bf74817a..ddecf34968fd 100644
@@ -3649,6 +3649,7 @@ static int qmp_combo_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	qmp->dev = dev;
+	dev_set_drvdata(dev, qmp);
 
 	qmp->orientation = TYPEC_ORIENTATION_NORMAL;
 
@@ -3725,8 +3726,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
 
 	phy_set_drvdata(qmp->dp_phy, qmp);
 
-	dev_set_drvdata(dev, qmp);
-
 	if (usb_np == dev->of_node)
 		phy_provider = devm_of_phy_provider_register(dev, qmp_combo_phy_xlate);
 	else
Signature · 1 line
2.44.2
#5 lore raw

Re: [PATCH 4/4] phy: qcom: qmp-usb: move driver data initialisation earlier

Quoted 4 lines · Johan Hovold

Commit 44aff8e31080 ("phy: qcom-qmp-combo: clean up probe initialisation") removed most users of the platform device driver data, but mistakenly also removed the initialisation despite the data still being used in the runtime PM callbacks.

Perhaps the copy/paste error in Subject can be fixed when applying. The summary was supposed to say:

phy: qcom: qmp-combo: move driver data initialisation earlier

and nothing else.

Johan

Reviewed-by on the v1 series
#6 lore raw
In reply to Johan Hovold
Quoted 5 lines · Johan Hovold

When working on suspend support for Qualcomm platforms like x1e80100, I ran into a NULL-pointer dereference in one of the QMP drivers. Turns out this issue has since been reproduced in two more drivers.

Johan

For the series:

Signature · 2 lines
With best wishes
Dmitry
#7 lore raw
In reply to Johan Hovold

Hi Vinod,

Quoted 9 lines · Johan Hovold

When working on suspend support for Qualcomm platforms like x1e80100, I ran into a NULL-pointer dereference in one of the QMP drivers. Turns out this issue has since been reproduced in two more drivers.

Johan Hovold (4):
phy: qcom: qmp-usb: fix NULL-deref on runtime suspend
phy: qcom: qmp-usb-legacy: fix NULL-deref on runtime suspend
phy: qcom: qmp-usbc: fix NULL-deref on runtime suspend
phy: qcom: qmp-usb: move driver data initialisation earlier

It's been a month (and a merge window) so sending a reminder.

Could you pick these up for 6.12-rc?

Johan

maintainer Applied
#8 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

When working on suspend support for Qualcomm platforms like x1e80100, I ran into a NULL-pointer dereference in one of the QMP drivers. Turns out this issue has since been reproduced in two more drivers.

Johan

[...]

Applied, thanks!

[1/4] phy: qcom: qmp-usb: fix NULL-deref on runtime suspend

      commit: bd9e4d4a3b127686efc60096271b0a44c3100061
[2/4] phy: qcom: qmp-usb-legacy: fix NULL-deref on runtime suspend
      commit: 29240130ab77c80bea1464317ae2a5fd29c16a0c
[3/4] phy: qcom: qmp-usbc: fix NULL-deref on runtime suspend
      commit: 34c21f94fa1e147a19b54b6adf0c93a623b70dd8
[4/4] phy: qcom: qmp-usb: move driver data initialisation earlier
      commit: 1dd196f9004848d0318e8831f962cc76255431d8

Best regards,

Signature · 1 line
~Vinod