* [PATCH] ASoC: rt5645: stop timer and delayed works on probe error
@ 2026-11-30 13:28 Yaohan Li
2026-11-30 13:32 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yaohan Li @ 2026-11-30 13:28 UTC (permalink / raw)
To: Oder Chiou, Liam Girdwood, Mark Brown
Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel
rt5645_i2c_probe() requests the threaded IRQ before calling
devm_snd_soc_register_component(). If component registration fails,
err_irq calls free_irq() without cancelling rt5645->jack_detect_work,
which the IRQ handler may already have queued to run 250 ms later after
devres frees rt5645.
Match rt5645_i2c_remove() in err_irq: shut down btn_check_timer and
cancel jack_detect_work and rcclock_work after free_irq() so no timer or
delayed work remains active when probe returns an error.
Fixes: cd6e82b814ca ("ASoC: rt5645: Add the workqueue of the jack detect function for the debouncing")
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Based on v7.4-rc5 (fe6ff8d5d675).
Tested in QEMU x86_64 (KASAN + PROVE_LOCKING) using a virtual I2C adapter
and a virtual IRQ controller (no physical rt5645 hardware). Failing
devm_snd_soc_register_component() via failslab while an IRQ fires queues
jack_detect_work, which runs after devres frees rt5645: unpatched hits
a KASAN slab-use-after-free in __run_timer_base on the first of 10/10
fault-injected iterations (single-shot KASAN); with this patch, 10/10
iterations complete and unload cleanly with 0 KASAN reports.
Note that only jack_detect_work was dynamically reproduced on this probe
failure path; btn_check_timer and rcclock_work are not armed while
rt5645->component is NULL and are torn down here to stay symmetric with
rt5645_i2c_remove() and prevent timer/work rearming across teardown.
Build-tested on x86_64 and arm64 with W=1 (0 warnings). Not tested on
physical hardware.
AI assistance: Claude (Anthropic) helped with the analysis, the QEMU test
harness, and drafting the patch and changelog. I reviewed the root cause,
teardown order, test results, and the final patch.
sound/soc/codecs/rt5645.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index e14b66d3118d..dbbd12e637e7 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -4282,6 +4282,9 @@ static int rt5645_i2c_probe(struct i2c_client *i2c)
err_irq:
if (rt5645->i2c->irq)
free_irq(rt5645->i2c->irq, rt5645);
+ timer_shutdown_sync(&rt5645->btn_check_timer);
+ cancel_delayed_work_sync(&rt5645->jack_detect_work);
+ cancel_delayed_work_sync(&rt5645->rcclock_work);
err_enable:
regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ASoC: rt5645: stop timer and delayed works on probe error
2026-11-30 13:28 [PATCH] ASoC: rt5645: stop timer and delayed works on probe error Yaohan Li
@ 2026-11-30 13:32 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 13:32 UTC (permalink / raw)
To: Yaohan Li; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] ASoC: rt5645: use-after-free in rt5645_jack_detect_work()
[1]
--
commit 6c5cfa8c0e2764c399b0e7cada712cfd7e7eb7a6
Author: Yaohan Li <shunsheng1218@gmail.com>
ASoC: rt5645: stop timer and delayed works on probe error
This commit shuts down btn_check_timer and cancels jack_detect_work and
rcclock_work on the err_irq path in rt5645_i2c_probe() if component
registration fails.
> diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
> index e14b66d3118da..dbbd12e637e7b 100644
> --- a/sound/soc/codecs/rt5645.c
> +++ b/sound/soc/codecs/rt5645.c
> @@ -4282,6 +4282,9 @@ static int rt5645_i2c_probe(struct i2c_client *i2c)
> err_irq:
> if (rt5645->i2c->irq)
> free_irq(rt5645->i2c->irq, rt5645);
> + timer_shutdown_sync(&rt5645->btn_check_timer);
> + cancel_delayed_work_sync(&rt5645->jack_detect_work);
> + cancel_delayed_work_sync(&rt5645->rcclock_work);
[Severity: Critical]
This problem wasn't introduced by this patch, but can rt5645_remove() trigger
a similar use-after-free in rt5645_jack_detect_work() [1] when the
ASoC sound card is unbound while the I2C device remains bound?
sound/soc/codecs/rt5645.c:rt5645_remove() {
struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
rt5645_reset(component);
kfree(rt5645->eq_param);
rt5645->eq_param = NULL;
}
When the sound card is unbound, the ASoC core frees the component and
machine driver jack structures, but rt5645_remove() neither clears
rt5645->component nor stops btn_check_timer and jack_detect_work. Because
the I2C IRQ remains active, a subsequent jack interrupt queues
rt5645_jack_detect_work(), which sees the dangling rt5645->component pointer
and dereferences the freed component and jack structures in
rt5645_jack_detect() and snd_soc_jack_report().
[1] https://sashiko.dev/#/bug/linux-adf839ae-82ba-4d0b-86a4-d5a143d295a8
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130132808.2078478-1-shunsheng1218@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 13:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 13:28 [PATCH] ASoC: rt5645: stop timer and delayed works on probe error Yaohan Li
2026-11-30 13:32 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox