* [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
* Re: [PATCH] ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy()
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
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 15:03 UTC (permalink / raw)
To: Yuansheng Yang; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ALSA: firewire-lib: Fixes trailer cites wrong commit for
double-free
--
commit 6e9bc1c90758880ff0ccb44d4ebbd1e733d08950
Author: Yuansheng Yang <0xbeac@gmail.com>
> ALSA: firewire-lib: clear protocol pointer in amdtp_stream_destroy()
>
> 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>
[Severity: Low]
Should the Fixes tag cite df075feefbd3 ("ALSA: firewire-lib: complete
AM824 data block processing layer") instead?
Commit 44c376b9596c ("ALSA: firewire-lib: suppress kernel warnings when
releasing uninitialized stream data") only added the early NULL check on
s->protocol in amdtp_stream_destroy().
The s->protocol allocation and kfree(s->protocol) without clearing the
pointer were introduced earlier by that commit, when drivers such as
fireworks already registered card->private_free before duplex stream
init. Pointing Fixes there keeps stable-backport tracking accurate:
Fixes: df075feefbd3 ("ALSA: firewire-lib: complete AM824 data block processing layer")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205145351.1712358-1-0xbeac@gmail.com?part=1
^ permalink raw reply [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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox