mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] power: supply: fix work-vs-devres teardown use-after-free
@ 2026-11-06 16:00 hyunjungg
  2026-11-06 16:00 ` [PATCH 1/3] power: supply: ltc2941: drain poll work before the power supply is unregistered hyunjungg
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-06 16:00 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm
  Cc: Chen-Yu Tsai, Matthias Brugger, AngeloGioacchino Del Regno,
	linux-arm-kernel, linux-mediatek, linux-kernel, Hyunjung Ko

From: Hyunjung Ko <hj351016@gmail.com>

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-06 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 16:00 [PATCH 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-06 16:00 ` [PATCH 1/3] power: supply: ltc2941: drain poll work before the power supply is unregistered hyunjungg
2026-11-06 16:00 ` [PATCH 2/3] power: supply: axp20x_usb_power: drain vbus_detect work before unregistering the supply hyunjungg
2026-11-06 16:00 ` [PATCH 3/3] power: supply: mt6360_charger: drain chrdet_work before the power supply is freed hyunjungg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®