Skip to content

Commit

Permalink
power: supply: generic-adc-battery: fix possible use-after-free in ga…
Browse files Browse the repository at this point in the history
…b_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 <[email protected]>
Signed-off-by: Yang Yingliang <[email protected]>
Signed-off-by: Sebastian Reichel <[email protected]>
  • Loading branch information
Yang Yingliang authored and sre committed Apr 8, 2021
1 parent e61ffb3 commit b6cfa00
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/power/supply/generic-adc-battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ static int gab_remove(struct platform_device *pdev)
}

kfree(adc_bat->psy_desc.properties);
cancel_delayed_work(&adc_bat->bat_work);
cancel_delayed_work_sync(&adc_bat->bat_work);
return 0;
}

Expand Down

0 comments on commit b6cfa00

Please sign in to comment.