From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796482449; b=sjOwzJBs5qXTN1tIWSuQ5DVRGy0XVlJE6x/4QCv+VYDPIkv/i1WY1DMM+fNACqTGllRo t5OEsb3xDw36Sxs6NpYAGiLcO192WEzURa+zgZJWN/xLPSMZQYcxnRpNrHJdASCqXzeYt yzuihlK2PSLlYf/dgc3FaxLCJnfubdJxYCexsSNaZjIu+Mhjj6QQj8ySLM8hKirvGwT1k zzlNbUc6dUcQKYS5JhryWPjKU0+ccvHKQZTV5h90cq+jq03W9v3Zi0DTajL6qi5fruftB J+R4V7nsh+LT0ih1MhVGaV+sieiUyiJivRZruPE8zOM9V/q752VrCv69SfM8euzRUTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796482449; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=WN1/Zn4jR6tVeiUcjnbbskzOB4jJs3UBikNvLonuaqw=; b=AX02jV7tDU55HXDu3YO5LCnH+zPKYEI5DA++29Jrsx6wgYIZtrOjQLzTXEF0vBMd0ONE cb0ijE08kE5vtwYWjoXDT4nJvUO59ytDOXoMEqrqor+qoowL7wDXv3CXQgyQ53yjj3WKt ia7TJQ4HiaYNAX2Ox/lk1tE5TWQv4qyREtbsxIoFKMAjc/aUrc6N3rNFJhY+imNC6bWUj od55Bby/E9lNqdnRIq3pSM8gjUqCmUWOKC3eHhPdiI1sh4ltK/ZaEI1vueYfF5K0y/CGN sNz6yK/BmUSo/zy5efIs9wds80Uqpg5YUja1WiAMGXIz9vzjPXo33+nCdy9wFuFVM1Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=m5uoFmDJ; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51F8E606A333 for ; Sat, 5 Dec 2026 14:54:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51F8E606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=m5uoFmDJ Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-387504e1934so2044711eec.1 for ; Sat, 05 Dec 2026 06:54:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796482447; x=1797087247; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=WN1/Zn4jR6tVeiUcjnbbskzOB4jJs3UBikNvLonuaqw=; b=m5uoFmDJ7NpMqSM15jVtzOUijMXv+w/pZny2zbSmI4Cb3XODCkighUNnTOeNOYHrjr qK0SB8ohiT8NP/bOfOxTL/Lqs/x3u5004k1s/XPnep4debaPLufHq9jxZ60GfePju6gr aehtIWnTmXHgXQyCE3yDbi0TC6PwCKdINdr7vQWmdU8NS+1B/SfruKta23FX3UOf7RDV kdtsZj21Z90Htw8wbJvPW/ZtsiE+JgaslicbOgTwTZ+iJQy/AMk3LSaP39YDA5JRBews UViyb5akIZzDAuCmflLgjbTRMpq62cHp9BmO6ETHaMtmZFq8a/KT4eK6MIt23v4K3LyG Eyfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796482447; x=1797087247; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WN1/Zn4jR6tVeiUcjnbbskzOB4jJs3UBikNvLonuaqw=; b=CbVWRNBRv2UNx4tcImMiHlnsDmuuO61AAjKYRdkXsI99uIU7fp7LzlbPhqaKhpyZEY i6nmwuwTm2nHPSA/O7VdGcQmsHZ4V3woQN//vlKSbN2eVtU7aZHst6cGb93aDq4gdlal Eqf0mjGH4U9ENyoO0sss3GAmJaJ8/WsLf300HgLUzLKdtBt1SA0chsXZMpIXHnAmIeTl ptLsIdwr2+0j56oCgoeU+pf0O8eNTUJNzfGL3n2e4gmwOq61nDobzZcL4xJJSRq65JQc EYEF6e+My0k1jboeydp5I43i8SBvorwgGfk7WWfrSV4lm0ZiR9K/SewQn0lPpPU+Pv0A HePg== X-Gm-Message-State: APuU4Z99UnOUBbM/o6WBFopv3F1nbhEWKt0PUIXyZc2h+gtkzKdcvGho SV2TCql/w54mW4QOgkTT6+X+rS7RJhkFPCKIDEVo6ROQvHJt1ljB5CIy X-Gm-Gg: AZFdTZcWD33lKtw9z7dK1AO7JreiyABDxMNwRyLMOlq58siYeZv1SWpVBdFddBkUst6 TNTfeBc28mAVrpTGF8Cvh2X03Bs4Ivbb69hOY4rhkyjqlFU+v2OkrmPfYWzRfAvL6xvdEjKMiaF K0JKgVsTU8iIR0Qez4vDUSOHWgxYO/9fsVyll9aSwDnxCUAuvRcPzjbcUHtv3gCKIB45lNrrHRO H4KS5PoAcxmWaDa57UyUGjQd+3ARgaMkzxLCeT4FpLAJzsAfjLerNhyU9xJKdx7CHxO9YV39uga E+/APr6dmJZHHU957TFx3Pbg+FVQ0LaQdSAFbcd94dRCHch1l9qFbKMT4THMu3VAu/yf4RpE8k1 3S+Yphw5NTYeYgg+XKDXmoIub4bHnxL0MLCcXyo0o+M2jx/zFEtm+8YhNS3zGFJTH72EARi289X tJTNEw4NBgSV5WQAf/355wEmGxJdntGvIVq+iRlnTHwUKy5SL0v2nrdpSAJhv7ypkdkPmfF5M+f M8VczpToOTU3QqiTo2JHxDQ1dM0LGrzprgl6HxnZ4oPAi+kebnos2rCZU+crGJTypsNNDwht/BM P3nGqX+SNqDijsGbQ9J3nr0c9M/+Ay+mAP0uAo0wkhZEu2MWqg6uEw== X-Received: by 2002:a05:7300:d0a1:b0:387:490c:a366 with SMTP id 5a478bee46e88-387521e4fedmr5455647eec.41.1796482447315; Sat, 05 Dec 2026 06:54:07 -0800 (PST) Received: from dell (pdf8686c5.kngwnt01.ap.so-net.ne.jp. [223.134.134.197]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bdedbsm20256292eec.12.2026.12.05.06.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 06:54:06 -0800 (PST) From: Yuansheng Yang <0xbeac@gmail.com> To: Clemens Ladisch , Takashi Sakamoto 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 Message-ID: <20261205145351.1712358-1-0xbeac@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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