]> Git Repo - linux.git/commitdiff
thermal: core: Fix use-after-free in thermal_cooling_device_destroy_sysfs
authorDmitry Osipenko <[email protected]>
Mon, 13 Aug 2018 17:14:00 +0000 (20:14 +0300)
committerZhang Rui <[email protected]>
Wed, 10 Oct 2018 03:44:52 +0000 (11:44 +0800)
This patch fixes use-after-free that was detected by KASAN. The bug is
triggered on a CPUFreq driver module unload by freeing 'cdev' on device
unregister and then using the freed structure during of the cdev's sysfs
data destruction. The solution is to unregister the sysfs at first, then
destroy sysfs data and finally release the cooling device.

Cc: <[email protected]> # v4.17+
Fixes: 8ea229511e06 ("thermal: Add cooling device's statistics in sysfs")
Signed-off-by: Dmitry Osipenko <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
Acked-by: Eduardo Valentin <[email protected]>
Signed-off-by: Zhang Rui <[email protected]>
drivers/thermal/thermal_core.c

index 6ab982309e6a04cd3c933850d34aabaaf3dd60e4..4417781008878eb616d194f89fd176c92acfc502 100644 (file)
@@ -1102,8 +1102,9 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
        mutex_unlock(&thermal_list_lock);
 
        ida_simple_remove(&thermal_cdev_ida, cdev->id);
-       device_unregister(&cdev->device);
+       device_del(&cdev->device);
        thermal_cooling_device_destroy_sysfs(cdev);
+       put_device(&cdev->device);
 }
 EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
 
This page took 0.055742 seconds and 4 git commands to generate.