[PATCH] ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy()
From: Yuansheng Yang
Date: Sat Dec 05 2026 - 09:54:12 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Yuansheng Yang <0xbeac@xxxxxxxxx>
---
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