Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: generic-adc-battery: fix possible use-after-free in gab_remove()

This driver's remove path calls cancel_delayed_work(). However, that
function does not wait until the work function finishes. This means
that the callback function may still be running after the driver's
remove function has finished, which would result in a use-after-free.

Fix by calling cancel_delayed_work_sync(), which ensures that
the work is properly cancelled, no longer running, and unable
to re-schedule itself.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Yang Yingliang and committed by
Sebastian Reichel
b6cfa007 e61ffb34

+1 -1
+1 -1
drivers/power/supply/generic-adc-battery.c
··· 373 373 } 374 374 375 375 kfree(adc_bat->psy_desc.properties); 376 - cancel_delayed_work(&adc_bat->bat_work); 376 + cancel_delayed_work_sync(&adc_bat->bat_work); 377 377 return 0; 378 378 } 379 379