Linux Power Management development
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Fan Wu <fanwu01@zju.edu.cn>
Cc: linux-pm@vger.kernel.org, laurentiu.palcu@intel.com,
	krzk@kernel.org,  linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] power: supply: bq24257: fix use-after-free on remove
Date: Fri, 31 Jul 2026 23:29:56 +0200	[thread overview]
Message-ID: <am0ShrO_o3lJ_V8L@venus> (raw)
In-Reply-To: <20260731143554.334179-1-fanwu01@zju.edu.cn>

[-- 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 --]

      reply	other threads:[~2026-07-31 21:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=am0ShrO_o3lJ_V8L@venus \
    --to=sebastian.reichel@collabora.com \
    --cc=fanwu01@zju.edu.cn \
    --cc=krzk@kernel.org \
    --cc=laurentiu.palcu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox