Skip to contentSkip to conversation

usb: typec: fix null-pointer-dereference in wcove_typec_probe()

PATCH In review Jeffin Philip 2 participants 4 messages Aug 21

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

PATCH 1/1 usb: typec: fix null-pointer-dereference in wcove_typec_probe()

dev_get_drvdata() on the parent device can return NULL if we attempt to bind our device as a root device with no parent. This causes a null pointer dereference when accessing pmic->regmap later as pmic uses the parent struct. Fix this by adding a NULL check for pmic and returning -ENODEV if to_platform_device() returns NULL for pmic.

Reported-by [email protected]
Fixes d2061f9cc32d ("usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY")
---
 drivers/usb/typec/tcpm/wcove.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/typec/tcpm/wcove.c +4 -0
index 0e5a3e277c3e..80bca8edeba6 100644
@@ -612,6 +612,10 @@ static int wcove_typec_probe(struct platform_device *pdev)
 	int irq;
 	int ret;
 
+	/* check if we have a parent device first */
+	if (!pmic)
+		return -ENODEV;
+
 	wcove = devm_kzalloc(&pdev->dev, sizeof(*wcove), GFP_KERNEL);
 	if (!wcove)
 		return -ENOMEM;
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 20 lines · Jeffin Philip

dev_get_drvdata() on the parent device can return NULL if we attempt to bind our device as a root device with no parent. This causes a null pointer dereference when accessing pmic->regmap later as pmic uses the parent struct. Fix this by adding a NULL check for pmic and returning -ENODEV if to_platform_device() returns NULL for pmic.

Reported-by [email protected]
Fixes d2061f9cc32d ("usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY")
---
 drivers/usb/typec/tcpm/wcove.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/typec/tcpm/wcove.c +0 -0
index 0e5a3e277c3e..80bca8edeba6 100644

drivers/usb/typec/tcpm/wcove.c static int wcove_typec_probe(struct platform_device *pdev) · line 617

Quoted 6 lines
drivers/usb/typec/tcpm/wcove.c +3 -0
@@ -612,6 +612,10 @@ static int wcove_typec_probe(struct platform_device *pdev)
 	int irq;
 	int ret;
 
+	/* check if we have a parent device first */
+	if (!pmic)
+		return -ENODEV;

How can a platform device NOT have a parent device? WHat system is this broken in? Why not fix the platform definition properly instead as something is really wrong here if this is a "root" platform device as that should never happen.

thanks,

greg k-h

#2 lore raw
Quoted 4 lines · Greg KH

How can a platform device NOT have a parent device? WHat system is this broken in? Why not fix the platform definition properly instead as something is really wrong here if this is a "root" platform device as that should never happen.

As seen in the Closes: tag, this is a syzbot issue. It used driver_override() to bind it in an unnatural way. So, I don't think it is possible in a real system. We could atleast validate pmic like other functions using dev_get_drvdata() or it could be left alone as is.

Thanks,
Jeffin.

maintainer
#3 lore raw
Quoted 10 lines · Jeffin Philip
Quoted 4 lines · Greg KH

How can a platform device NOT have a parent device? WHat system is this broken in? Why not fix the platform definition properly instead as something is really wrong here if this is a "root" platform device as that should never happen.

As seen in the Closes: tag, this is a syzbot issue. It used driver_override() to bind it in an unnatural way. So, I don't think it is possible in a real system. We could atleast validate pmic like other functions using dev_get_drvdata() or it could be left alone as is.

If you call bind on a device, you have to know what you are doing, as it can easily crash as you see here. Just fix syzbot please.