* [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free
@ 2026-11-09 4:42 hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, 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 work for devm
cancellation before devm_power_supply_register(). devres unwinds in
reverse, so on unbind the power supply is freed before the work is
cancelled, and the work's power_supply_changed() then dereferences the
freed supply. Each patch moves the devm work-cancel registration to after
devm_power_supply_register() so teardown drains the work first. No
functional change.
v2 (thanks Sebastian Reichel):
- trim the commit messages down to the bug and the fix
- drop the inline comments
- no code change vs v1 other than that comment removal
Hyunjung Ko (3):
power: supply: ltc2941: drain poll work before unregistering the supply
power: supply: axp20x_usb_power: drain vbus_detect work before
unregistering the supply
power: supply: mt6360_charger: drain chrdet_work before unregistering
the supply
drivers/power/supply/axp20x_usb_power.c | 10 +++++-----
drivers/power/supply/ltc2941-battery-gauge.c | 10 +++++-----
drivers/power/supply/mt6360_charger.c | 7 ++++---
3 files changed, 14 insertions(+), 13 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
@ 2026-11-09 4:42 ` hyunjungg
2026-11-09 4:42 ` [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect " hyunjungg
2026-11-09 4:42 ` [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work " hyunjungg
2 siblings, 0 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, Chen-Yu Tsai, Matthias Brugger,
AngeloGioacchino Del Regno, linux-arm-kernel, linux-mediatek,
linux-kernel, Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
ltc294x_i2c_probe() registers the poll work for devm cancellation before
devm_power_supply_register(). devres unwinds in reverse, so on unbind the
power supply is freed first and the work cancelled last. ltc294x_work()
re-queues itself and calls power_supply_changed(info->supply), so a poll
instance running in that window dereferences the freed supply.
Register the work cancellation after the power supply so devres drains it
first. Nothing queues the work before the schedule_delayed_work() that
follows, so the move is safe.
Fixes: 6d0c5de2fd84 ("power: supply: Clean-up few drivers by using managed work init")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
index 6ebb555..8f8a8f6 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -531,11 +531,6 @@ static int ltc294x_i2c_probe(struct i2c_client *client)
psy_cfg.drv_data = info;
- ret = devm_delayed_work_autocancel(&client->dev, &info->work,
- ltc294x_work);
- if (ret)
- return ret;
-
ret = ltc294x_reset(info, prescaler_exp);
if (ret < 0)
return dev_err_probe(&client->dev, ret,
@@ -547,6 +542,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client)
return dev_err_probe(&client->dev, PTR_ERR(info->supply),
"failed to register ltc2941\n");
+ ret = devm_delayed_work_autocancel(&client->dev, &info->work,
+ ltc294x_work);
+ if (ret)
+ return ret;
+
schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ);
return 0;
--
2.43.0
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect work before unregistering the supply
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
@ 2026-11-09 4:42 ` hyunjungg
2026-11-09 4:42 ` [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work " hyunjungg
2 siblings, 0 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, Chen-Yu Tsai, Matthias Brugger,
AngeloGioacchino Del Regno, linux-arm-kernel, linux-mediatek,
linux-kernel, Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
axp20x_usb_power_probe() registers the vbus_detect poll work for devm
cancellation before devm_power_supply_register(). devres unwinds in
reverse, so on unbind the power supply is freed first and the work
cancelled last. The handler calls power_supply_changed(power->supply) and
re-queues itself (and is also queued from the USB power IRQ), so an
instance running in that window dereferences the freed supply.
Register the work cancellation after the power supply, matching the
"request irqs after registering" ordering already used below.
Fixes: 6d0c5de2fd84 ("power: supply: Clean-up few drivers by using managed work init")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
index 7625366104bc..f6a7dcbd5a01 100644
--- a/drivers/power/supply/axp20x_usb_power.c
+++ b/drivers/power/supply/axp20x_usb_power.c
@@ -979,11 +979,6 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
if (ret)
return ret;
- ret = devm_delayed_work_autocancel(dev, &power->vbus_detect,
- axp_data->axp20x_read_vbus);
- if (ret)
- return ret;
-
if (power->vbus_mon_bit) {
/* Enable vbus valid checking */
ret = regmap_field_write(power->vbus_mon_bit, 1);
@@ -1018,6 +1013,11 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(power->supply),
"Failed to register power supply\n");
+ ret = devm_delayed_work_autocancel(dev, &power->vbus_detect,
+ axp_data->axp20x_read_vbus);
+ if (ret)
+ return ret;
+
/* Request irqs after registering, as irqs may trigger immediately */
for (i = 0; i < axp_data->num_irq_names; i++) {
irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work before unregistering the supply
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
2026-11-09 4:42 ` [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect " hyunjungg
@ 2026-11-09 4:42 ` hyunjungg
2 siblings, 0 replies; 4+ messages in thread
From: hyunjungg @ 2026-11-09 4:42 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm
Cc: Sebastian Reichel, Chen-Yu Tsai, Matthias Brugger,
AngeloGioacchino Del Regno, linux-arm-kernel, linux-mediatek,
linux-kernel, Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
mt6360_charger_probe() registers chrdet_work for devm cancellation before
devm_power_supply_register(). devres unwinds in reverse, so on unbind the
power supply is freed first and the work cancelled last.
mt6360_chrdet_work() calls power_supply_changed(mci->psy), so the work
running in that window dereferences the freed supply.
Register the work cancellation after the power supply so devres drains it
first. chrdet_work is only scheduled later in probe, so the move is safe.
Fixes: 0402e8ebb8b8 ("power: supply: mt6360_charger: add MT6360 charger support")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
diff --git a/drivers/power/supply/mt6360_charger.c b/drivers/power/supply/mt6360_charger.c
index b4d462343151..71c60ba012df 100644
--- a/drivers/power/supply/mt6360_charger.c
+++ b/drivers/power/supply/mt6360_charger.c
@@ -790,9 +790,6 @@ static int mt6360_charger_probe(struct platform_device *pdev)
mci->vinovp = 6500000;
mutex_init(&mci->chgdet_lock);
platform_set_drvdata(pdev, mci);
- ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "Failed to set delayed work\n");
ret = device_property_read_u32(&pdev->dev, "richtek,vinovp-microvolt", &mci->vinovp);
if (ret)
@@ -828,6 +825,10 @@ static int mt6360_charger_probe(struct platform_device *pdev)
if (IS_ERR(mci->otg_rdev))
return PTR_ERR(mci->otg_rdev);
+ ret = devm_work_autocancel(&pdev->dev, &mci->chrdet_work, mt6360_chrdet_work);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to set delayed work\n");
+
schedule_work(&mci->chrdet_work);
return 0;
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-09 4:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 4:42 [PATCH v2 0/3] power: supply: fix work-vs-devres teardown use-after-free hyunjungg
2026-11-09 4:42 ` [PATCH v2 1/3] power: supply: ltc2941: drain poll work before unregistering the supply hyunjungg
2026-11-09 4:42 ` [PATCH v2 2/3] power: supply: axp20x_usb_power: drain vbus_detect " hyunjungg
2026-11-09 4:42 ` [PATCH v2 3/3] power: supply: mt6360_charger: drain chrdet_work " 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®