From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8F0952BE36 for ; Wed, 9 Sep 2026 11:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788954467; cv=none; b=G5gm4Tsp2aoh9EH9d1uQ7o43dAckrRrSJz6LqO1yY6KFmNv2SZsxKgc1RgC6J48BcBF8goy/vKnkhrmgfhS3/MhIs8G2Q9yUVpulvfRZOc5VRKVQSn2D9kz//qb4y2eiLXCnH3g/9/22FumRR18J2q8a/eRbbYY0smwEJRqiPVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788954467; c=relaxed/simple; bh=28BseIwsVssx6gY49+br4YluAT9k7cwvRiB3vevVS/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RPbo9oNHquYez+yV+wzNLpcl7dFceogOfE8N3suRUas/H/IVfGTjZas0lXLlKJVl3NCNi5wE9JaK9EoibGOW434AL1avCVTZEMB9guNBYZTzAbmWgXGfMDz/zdBvyO/rifts1UHH9ixaft0nUPFDW+kl50LaNchd9R1hyLt2u6c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E+R1YqrS; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E+R1YqrS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A6FC1F00A3D; Wed, 9 Sep 2026 11:47:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788954464; bh=WwKwMgjTTc7bBUxG7mRUm6psM9RUK1XAHvzPe7BAiV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E+R1YqrSMgZPQwuJviTawl7bgi5UFeU8J0O4QlPmeoTGGJTAG0bnlHvje9WrnyVPg mtWeNUR2AdcK5YXjqdcQ3KqTudB8hpiZHOOVQs9n6+AuocliQ8ikyx3KvVRgOU7P52 +ToGoUiAgwUHnlRzGJqznZzgCzM4FxxwCVabWGYExFFMs112MNwDk9vlrI0cOfocm/ Fdeails7hMGa6KQ1FLw9pNCefoVSBjBukN7kPV7Y0881KcMKmFnwtTpQrtN988Faxg J6Y6ynIXOUgekqEdhcEoTo+6LgB5jEwf0o5xax+JkIH6RSnX3Bi33ERNvxgtrz9rFB xfzayJBP9ok3A== From: Sasha Levin To: stable@vger.kernel.org Cc: Fan Wu , Linus Walleij , Sebastian Reichel , Sasha Levin Subject: [PATCH 6.1.y 2/2] power: supply: ab8500_fg: fix use-after-free on remove Date: Wed, 9 Sep 2026 07:47:41 -0400 Message-ID: <20260909114741.2012696-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260909114741.2012696-1-sashal@kernel.org> References: <2026090322-cradling-finance-beb1@gregkh> <20260909114741.2012696-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Fan Wu [ Upstream commit 75b1e88d34254f4fb7753345e21bfee47abddd7f ] ab8500_fg_remove() destroys the driver workqueue while the threaded interrupt handlers are still armed; they are devm-managed and freed only after ->remove() returns, so a handler that fires in that window queues work on the freed workqueue. Tear the workqueue down through devm instead, registering its cleanup after the power supply and before the interrupt requests. devm then frees the interrupts first, so the handlers can no longer queue work, before disabling the delayed and plain work items and destroying the workqueue. Disabling the items, rather than cancelling them, keeps them disabled so no producer (including the power-supply external_power_changed callback) can requeue them. Found by an in-house static analysis tool. Fixes: 13151631b5bd ("ab8500-fg: A8500 fuel gauge driver") Cc: stable@vger.kernel.org # v6.10+ Assisted-by: Codex:gpt-5.6 Signed-off-by: Fan Wu Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260802020316.417757-1-fanwu01@zju.edu.cn Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/ab8500_fg.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index bb4ad449391f0..366de6b2decce 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -3061,6 +3061,20 @@ static void ab8500_fg_unbind(struct device *dev, struct device *master, flush_workqueue(di->fg_wq); } +/* Disable, not cancel: works stay disabled so nothing can re-arm them. */ +static void ab8500_fg_destroy_workqueue(void *data) +{ + struct ab8500_fg *di = data; + + disable_work_sync(&di->fg_acc_cur_work); + disable_work_sync(&di->fg_work); + disable_delayed_work_sync(&di->fg_reinit_work); + disable_delayed_work_sync(&di->fg_low_bat_work); + disable_delayed_work_sync(&di->fg_check_hw_failure_work); + disable_delayed_work_sync(&di->fg_periodic_work); + destroy_workqueue(di->fg_wq); +} + static const struct component_ops ab8500_fg_component_ops = { .bind = ab8500_fg_bind, .unbind = ab8500_fg_unbind, @@ -3162,6 +3176,11 @@ static int ab8500_fg_probe(struct platform_device *pdev) return PTR_ERR(di->fg_psy); } + /* Registered after fg_psy, before the IRQs: devm frees IRQ -> workqueue -> fg_psy. */ + ret = devm_add_action_or_reset(dev, ab8500_fg_destroy_workqueue, di); + if (ret) + return ret; + di->fg_samples = SEC_TO_SAMPLE(di->bm->fg_params->init_timer); /* @@ -3174,20 +3193,16 @@ static int ab8500_fg_probe(struct platform_device *pdev) /* Register primary interrupt handlers */ for (i = 0; i < ARRAY_SIZE(ab8500_fg_irq); i++) { irq = platform_get_irq_byname(pdev, ab8500_fg_irq[i].name); - if (irq < 0) { - destroy_workqueue(di->fg_wq); + if (irq < 0) return irq; - } ret = devm_request_threaded_irq(dev, irq, NULL, ab8500_fg_irq[i].isr, IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT, ab8500_fg_irq[i].name, di); - if (ret != 0) { - destroy_workqueue(di->fg_wq); + if (ret != 0) return ret; - } dev_dbg(dev, "Requested %s IRQ %d: %d\n", ab8500_fg_irq[i].name, irq, ret); } @@ -3201,7 +3216,6 @@ static int ab8500_fg_probe(struct platform_device *pdev) ret = ab8500_fg_sysfs_init(di); if (ret) { dev_err(dev, "failed to create sysfs entry\n"); - destroy_workqueue(di->fg_wq); return ret; } @@ -3209,7 +3223,6 @@ static int ab8500_fg_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "failed to create FG psy\n"); ab8500_fg_sysfs_exit(di); - destroy_workqueue(di->fg_wq); return ret; } @@ -3229,7 +3242,6 @@ static int ab8500_fg_remove(struct platform_device *pdev) { struct ab8500_fg *di = platform_get_drvdata(pdev); - destroy_workqueue(di->fg_wq); component_del(&pdev->dev, &ab8500_fg_component_ops); list_del(&di->node); ab8500_fg_sysfs_exit(di); -- 2.53.0