Skip to contentSkip to conversation

platform/chrome: wilco_ec: fix use after free issue

PATCH In review Wen Yang 2 participants 2 messages Nov 30, 2019 – Dec 2, 2019 Chrome hardware platform support

lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 platform/chrome: wilco_ec: fix use after free issue

This is caused by dereferencing 'dev_data' after put_device() in the telem_device_remove() function.
This patch just moves the put_device() down a bit to avoid this issue.

Fixes 1210d1e6bad1 ("platform/chrome: wilco_ec: Add telemetry char device interface")
Cc Benson Leung <[email protected]>
Cc Enric Balletbo i Serra <[email protected]>
Cc Nick Crews <[email protected]>
---
 drivers/platform/chrome/wilco_ec/telemetry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/wilco_ec/telemetry.c +1 -1
index b9d03c3..1176d54 100644
@@ -406,8 +406,8 @@ static int telem_device_remove(struct platform_device *pdev)
 	struct telem_device_data *dev_data = platform_get_drvdata(pdev);
 
 	cdev_device_del(&dev_data->cdev, &dev_data->dev);
-	put_device(&dev_data->dev);
 	ida_simple_remove(&telem_ida, MINOR(dev_data->dev.devt));
+	put_device(&dev_data->dev);
 
 	return 0;
 }
Signature · 1 line
1.8.3.1
#1 lore raw

Hi Wen,

Quoted 5 lines · Wen Yang

This is caused by dereferencing 'dev_data' after put_device() in the telem_device_remove() function.
This patch just moves the put_device() down a bit to avoid this issue.

Quoted 7 lines
Fixes 1210d1e6bad1 ("platform/chrome: wilco_ec: Add telemetry char device interface")
Cc Benson Leung <[email protected]>
Cc Enric Balletbo i Serra <[email protected]>
Cc Nick Crews <[email protected]>

---

Queued for 5.5 as is a fix.

Thanks.
Enric

Quoted 18 lines
 drivers/platform/chrome/wilco_ec/telemetry.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/wilco_ec/telemetry.c +1 -1
index b9d03c3..1176d54 100644
@@ -406,8 +406,8 @@ static int telem_device_remove(struct platform_device *pdev)
 	struct telem_device_data *dev_data = platform_get_drvdata(pdev);
 
 	cdev_device_del(&dev_data->cdev, &dev_data->dev);
-	put_device(&dev_data->dev);
 	ida_simple_remove(&telem_ida, MINOR(dev_data->dev.devt));
+	put_device(&dev_data->dev);
 
 	return 0;
 }