From: "matteo.cotifava" <cotifavamatteo@gmail.com>
To: broonie@kernel.org
Cc: cotifavamatteo@gmail.com, cujomalainey@chromium.org,
lgirdwood@gmail.com, linux-kernel@vger.kernel.org,
linux-sound@vger.kernel.org, perex@perex.cz, srini@kernel.org,
tiwai@suse.com
Subject: [PATCH v2 2/2] ASoC: soc-core: flush delayed work before removing DAIs and widgets
Date: Mon, 9 Mar 2026 22:54:12 +0100 [thread overview]
Message-ID: <20260309215412.545628-3-cotifavamatteo@gmail.com> (raw)
In-Reply-To: <20260309215412.545628-1-cotifavamatteo@gmail.com>
When a sound card is unbound while a PCM stream is open, a
use-after-free can occur in snd_soc_dapm_stream_event(), called from
the close_delayed_work workqueue handler.
During unbind, snd_soc_unbind_card() flushes delayed work and then
calls soc_cleanup_card_resources(). Inside cleanup,
snd_card_disconnect_sync() releases all PCM file descriptors, and
the resulting PCM close path can call snd_soc_dapm_stream_stop()
which schedules new delayed work with a pmdown_time timer delay.
Since this happens after the flush in snd_soc_unbind_card(), the
new work is not caught. soc_remove_link_components() then frees
DAPM widgets before this work fires, leading to the use-after-free.
The existing flush in soc_free_pcm_runtime() also cannot help as it
runs after soc_remove_link_components() has already freed the widgets.
Add a flush in soc_cleanup_card_resources() after
snd_card_disconnect_sync() (after which no new PCM closes can
schedule further delayed work) and before soc_remove_link_dais()
and soc_remove_link_components() (which tear down the structures the
delayed work accesses).
Fixes: e894efef9ac7 ("ASoC: core: add support to card rebind")
Signed-off-by: Matteo Cotifava <cotifavamatteo@gmail.com>
---
sound/soc/soc-core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index e5ac8ae1665d..cf826c2a8b59 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2121,6 +2121,9 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
for_each_card_rtds(card, rtd)
if (rtd->initialized)
snd_soc_link_exit(rtd);
+ /* flush delayed work before removing DAIs and DAPM widgets */
+ snd_soc_flush_all_delayed_work(card);
+
/* remove and free each DAI */
soc_remove_link_dais(card);
soc_remove_link_components(card);
--
2.39.5
next prev parent reply other threads:[~2026-03-09 21:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 11:09 [PATCH] ASoC: soc-core: fix use-after-free in snd_soc_unbind_card() Matteo Cotifava
2026-03-09 15:01 ` Mark Brown
2026-03-09 21:49 ` matteo.cotifava
2026-03-09 21:54 ` [PATCH v2 0/2] ASoC: soc-core: fix use-after-free in close_delayed_work matteo.cotifava
2026-03-09 21:54 ` [PATCH v2 1/2] ASoC: soc-core: drop delayed_work_pending() check before flush matteo.cotifava
2026-03-09 21:54 ` matteo.cotifava [this message]
2026-03-09 22:08 ` [PATCH v2 0/2] ASoC: soc-core: fix use-after-free in close_delayed_work Mark Brown
2026-03-10 0:36 ` Mark Brown
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=20260309215412.545628-3-cotifavamatteo@gmail.com \
--to=cotifavamatteo@gmail.com \
--cc=broonie@kernel.org \
--cc=cujomalainey@chromium.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=srini@kernel.org \
--cc=tiwai@suse.com \
/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
all inboxes | Powered by JetHome®