* [PATCH] power: supply: bq24257: fix use-after-free on remove
@ 2026-07-31 14:35 Fan Wu
2026-07-31 21:29 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Fan Wu @ 2026-07-31 14:35 UTC (permalink / raw)
To: linux-pm; +Cc: sre, laurentiu.palcu, krzk, linux-kernel, stable, Fan Wu
The STAT-pin interrupt is devm-managed, so it stays armed until the devm
cleanup that runs after remove() returns. remove() cancels
bq->iilimit_setup_work while the handler can still fire; the threaded
handler reschedules that work and dereferences bq, so the work runs
against freed memory once devm frees bq.
Call devm_free_irq() before canceling the work so the handler is quiesced
and cannot reschedule it after the cancel.
Found by static analysis.
Fixes: 2219a935963e ("power_supply: Add TI BQ24257 charger driver")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.6
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
drivers/power/supply/bq24257_charger.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
index 72f1bfea8d..b9110d5fe2 100644
--- a/drivers/power/supply/bq24257_charger.c
+++ b/drivers/power/supply/bq24257_charger.c
@@ -1064,6 +1064,7 @@ static void bq24257_remove(struct i2c_client *client)
{
struct bq24257_device *bq = i2c_get_clientdata(client);
+ devm_free_irq(&client->dev, client->irq, bq);
if (bq->iilimit_autoset_enable)
cancel_delayed_work_sync(&bq->iilimit_setup_work);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: bq24257: fix use-after-free on remove
2026-07-31 14:35 [PATCH] power: supply: bq24257: fix use-after-free on remove Fan Wu
@ 2026-07-31 21:29 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2026-07-31 21:29 UTC (permalink / raw)
To: Fan Wu; +Cc: linux-pm, laurentiu.palcu, krzk, linux-kernel, stable
[-- Attachment #1: Type: text/plain, Size: 1797 bytes --]
Hi,
On Fri, Jul 31, 2026 at 02:35:54PM +0000, Fan Wu wrote:
> The STAT-pin interrupt is devm-managed, so it stays armed until the devm
> cleanup that runs after remove() returns. remove() cancels
> bq->iilimit_setup_work while the handler can still fire; the threaded
> handler reschedules that work and dereferences bq, so the work runs
> against freed memory once devm frees bq.
>
> Call devm_free_irq() before canceling the work so the handler is quiesced
> and cannot reschedule it after the cancel.
>
> Found by static analysis.
>
> Fixes: 2219a935963e ("power_supply: Add TI BQ24257 charger driver")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:gpt-5.6
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
> ---
Instead of this, which renders the device managed part of the IRQ
request pointless, just make the delayed work also device
managed and thus ordered correctly:
1. Move the INIT_DELAYED_WORK() block directly before the IRQ registration
2. Replace INIT_DELAYED_WORK() with devm_delayed_work_autocancel()
3. Drop the now pointless cancel_delayed_work_sync() from remove function
Greetings,
-- Sebastian
> drivers/power/supply/bq24257_charger.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
> index 72f1bfea8d..b9110d5fe2 100644
> --- a/drivers/power/supply/bq24257_charger.c
> +++ b/drivers/power/supply/bq24257_charger.c
> @@ -1064,6 +1064,7 @@ static void bq24257_remove(struct i2c_client *client)
> {
> struct bq24257_device *bq = i2c_get_clientdata(client);
>
> + devm_free_irq(&client->dev, client->irq, bq);
> if (bq->iilimit_autoset_enable)
> cancel_delayed_work_sync(&bq->iilimit_setup_work);
>
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-31 21:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 14:35 [PATCH] power: supply: bq24257: fix use-after-free on remove Fan Wu
2026-07-31 21:29 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox