Skip to content

Commit

Permalink
thermal: core: Fix use-after-free in thermal_cooling_device_destroy_s…
Browse files Browse the repository at this point in the history
…ysfs

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: <stable@vger.kernel.org> # v4.17+
Fixes: 8ea2295 ("thermal: Add cooling device's statistics in sysfs")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
  • Loading branch information
Dmitry Osipenko authored and Zhang Rui committed Oct 10, 2018
1 parent 0238df6 commit 3c58776
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3c58776

Please sign in to comment.