From: Yuansheng Yang <0xbeac@gmail.com>
To: Clemens Ladisch <clemens@ladisch.de>,
Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy()
Date: Sat, 5 Dec 2026 22:53:51 +0800 [thread overview]
Message-ID: <20261205145351.1712358-1-0xbeac@gmail.com> (raw)
amdtp_stream_destroy() guards against destroying an uninitialized or
already-destroyed stream by checking if s->protocol is NULL, then frees
s->protocol via kfree() without resetting s->protocol to NULL.
All ALSA FireWire drivers using snd_*_stream_init_duplex() (bebob, dice,
digi00x, fireface, fireworks, motu, oxfw, and tascam) register
card->private_free (which invokes snd_*_stream_destroy_duplex() ->
amdtp_stream_destroy()) before calling snd_*_stream_init_duplex(). When
snd_*_stream_init_duplex() fails after initializing at least one stream
(for example, when snd_efw_command_set_tx_mode() fails after tx_stream
and rx_stream have been initialized in snd_efw_stream_init_duplex(), or
on any mid-duplex stream or domain initialization error),
snd_*_stream_init_duplex() calls amdtp_stream_destroy() internally and
leaves s->protocol dangling. The driver's probe error path then calls
snd_card_free(), invoking amdtp_stream_destroy() a second time on the
already-freed pointer:
BUG: KASAN: double-free in amdtp_stream_destroy
Call Trace:
kfree
amdtp_stream_destroy
snd_efw_stream_destroy_duplex
release_card_device
snd_card_free
Clear s->protocol to NULL after kfree(s->protocol) in
amdtp_stream_destroy() so a second call returns early at the NULL check,
avoiding both the double kfree() and destroying s->mutex twice.
Fixes: 44c376b9596c ("ALSA: firewire-lib: suppress kernel warnings when releasing uninitialized stream data")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Compiled sound/firewire/amdtp-stream.o with W=1 on x86_64 (0 warnings,
0 errors) and verified on v7.4-rc5 in an x86_64 KASAN QEMU guest by
triggering snd_efw_stream_init_duplex() failure followed by
snd_card_free(): before this fix, KASAN reports a double-free in
amdtp_stream_destroy(); after this fix, 10/10 iterations unwind cleanly
with 0 KASAN, BUG, or WARNING diagnostics.
sound/firewire/amdtp-stream.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index 8e70da850..fd6d070cf 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -131,6 +131,7 @@ void amdtp_stream_destroy(struct amdtp_stream *s)
WARN_ON(amdtp_stream_running(s));
kfree(s->protocol);
+ s->protocol = NULL;
mutex_destroy(&s->mutex);
}
EXPORT_SYMBOL(amdtp_stream_destroy);
--
2.53.0
next reply other threads:[~2026-12-05 14:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 14:53 Yuansheng Yang [this message]
2026-12-05 15:03 ` [PATCH] ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy() sashiko-bot
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=20261205145351.1712358-1-0xbeac@gmail.com \
--to=0xbeac@gmail.com \
--cc=clemens@ladisch.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=o-takashi@sakamocchi.jp \
--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