All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy()
@ 2026-12-05 14:53 Yuansheng Yang
  2026-12-05 15:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yuansheng Yang @ 2026-12-05 14:53 UTC (permalink / raw)
  To: Clemens Ladisch, Takashi Sakamoto; +Cc: linux-sound, linux-kernel, stable

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:53 [PATCH] ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy() Yuansheng Yang
2026-12-05 15:03 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.