[PATCH 0/3] power: supply: fix work-vs-devres teardown use-after-free
From: hyunjungg
Date: Fri Nov 06 2026 - 11:01:26 EST
From: Hyunjung Ko <hj351016@xxxxxxxxx>
Three power-supply drivers register a poll/detect/charger-detect work for
device-managed cancellation (devm_[delayed_]work_autocancel()) in their probe
*before* they register the power_supply via devm_power_supply_register(). devres
unwinds in reverse order, so on unbind the power_supply device is released first
and the work is cancelled last. The work handlers call power_supply_changed()
and dereference the power_supply, so a work instance still pending/running in
that window touches the already-freed power_supply device -> use-after-free.
Each patch moves the devm work-cancel registration to *after*
devm_power_supply_register() (and before the IRQ/poll that arms the work), so
teardown drains the work before the power_supply is freed. No functional change
otherwise. The relocated devm_[delayed_]work_autocancel() still runs its INIT
before the work's first queue site, so no queue-before-INIT window is added.
This is the same class as the recently-applied cimax2/extcon work-vs-devres
fixes. Found by static analysis / code review; none is reproduced on hardware
(each needs its charger/PMIC/gauge chip and is not QEMU-reproducible) -- treat
accordingly.
Hyunjung Ko (3):
power: supply: ltc2941: drain poll work before the power supply is
unregistered
power: supply: axp20x_usb_power: drain vbus_detect work before
unregistering the supply
power: supply: mt6360_charger: drain chrdet_work before the power
supply is freed
drivers/power/supply/axp20x_usb_power.c | 16 +++++++++++-----
drivers/power/supply/ltc2941-battery-gauge.c | 10 +++++-----
drivers/power/supply/mt6360_charger.c | 13 ++++++++++---
3 files changed, 26 insertions(+), 13 deletions(-)
--
2.43.0