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

power: supply: s3c_adc_battery: fix possible use-after-free in s3c_adc_bat_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>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Yang Yingliang and committed by
Sebastian Reichel
68ae2569 b6cfa007

+1 -1
+1 -1
drivers/power/supply/s3c_adc_battery.c
··· 390 390 if (main_bat.charge_finished) 391 391 free_irq(gpiod_to_irq(main_bat.charge_finished), NULL); 392 392 393 - cancel_delayed_work(&bat_work); 393 + cancel_delayed_work_sync(&bat_work); 394 394 395 395 if (pdata->exit) 396 396 pdata->exit();