From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D409477E57; Tue, 16 Jun 2026 17:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781631489; cv=none; b=JKF/uty8xkqixLtxC4ZqxeEzNWDhLnIwS5jVN4WpkaF2L2iUXcEk/NzoE4TXS/ONKlOlLYz+GQcvSxYZDCc9wDiPnGP6UBacb1zGXapdpVghmYAZAfTTBgGaWc2w3DM0IY04llI1pyUwrZQ671bw2DTzSt1+KjxMrz2KTkoLdGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781631489; c=relaxed/simple; bh=q8cv5hlTHUHfxjehT52Dcsgn1VR2Z85PvTH6x3n7BQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=twYEoIsSzXVziHh5dbNyMOAfFSsoI9bO9cRVQ3FUujciXP+fXy2pcinm38wokwVWE2szTdLk4HDIcEIf8rk0RPRiwy1ExY+libzKAEuLRw8HvaLgkXD4eDO+Q3Ahw4FSH2XalfIDUifTho+rISIRE2llQxQV/QIDkHIjlf+Hx8M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=XkLzbaYT; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="XkLzbaYT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46E861F000E9; Tue, 16 Jun 2026 17:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781631488; bh=sDjKQP31WqEyUZkZyRr7RA4esweLiyqaBAYRv7pVgss=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XkLzbaYTa7qi2OnDFclQGJocnjkapPUMSvLNttckn/SdutVVZqSpnQhG90xKvOlAB NUpShQyp+SXbtnGzgyZJD+RkF6k/DBViBjo717ULdFQPHioAXC9nlvdT4V+Gu4mh6F pK6Hc6KUvzaYGmGKtAScDhrR/1pvQlQJyUAf9jjE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jian Zhou , Takashi Iwai , Sasha Levin Subject: [PATCH 6.1 230/522] ALSA: PCM: Fix wait queue list corruption in snd_pcm_drain() on linked streams Date: Tue, 16 Jun 2026 20:26:17 +0530 Message-ID: <20260616145136.758365781@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145125.307082728@linuxfoundation.org> References: <20260616145125.307082728@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ji'an Zhou [ Upstream commit 88fe2e3658726cb21ff2dcf9770bf672f9b9d31b ] snd_pcm_drain() uses init_waitqueue_entry which does not clear entry.prev/next, and add_wait_queue with a conditional remove_wait_queue that is skipped when to_check is no longer in the group after concurrent UNLINK. The orphaned wait entry remains on the unlinked substream sleep queue. On the next drain iteration, add_wait_queue adds the entry to a new queue while still linked on the old one, corrupting both lists. A subsequent wake_up dereferences NULL at the func pointer (mapped from the spinlock at offset 0 of the misinterpreted wait_queue_head_t), causing a kernel panic. Replace init_waitqueue_entry/add_wait_queue/conditional remove_wait_queue with init_wait_entry/prepare_to_wait/ finish_wait. init_wait_entry clears prev/next via INIT_LIST_HEAD on each iteration and sets autoremove_wake_function which auto-removes the entry on wake-up. finish_wait safely handles both the already-removed and still-queued cases. Fixes: 9b1dbd69ba6f ("ALSA: pcm: fix use-after-free on linked stream runtime in snd_pcm_drain") Signed-off-by: Ji'an Zhou Link: https://patch.msgid.link/20260604142559.3840881-1-eilaimemedsnaimel@gmail.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/pcm_native.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 7be5f25612b954..2ed9abb911a7aa 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2178,9 +2178,8 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream, drain_no_period_wakeup = to_check->no_period_wakeup; drain_rate = to_check->rate; drain_bufsz = to_check->buffer_size; - init_waitqueue_entry(&wait, current); - set_current_state(TASK_INTERRUPTIBLE); - add_wait_queue(&to_check->sleep, &wait); + init_wait_entry(&wait, 0); + prepare_to_wait(&to_check->sleep, &wait, TASK_INTERRUPTIBLE); snd_pcm_stream_unlock_irq(substream); if (drain_no_period_wakeup) tout = MAX_SCHEDULE_TIMEOUT; @@ -2198,7 +2197,7 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream, group = snd_pcm_stream_group_ref(substream); snd_pcm_group_for_each_entry(s, substream) { if (s->runtime == to_check) { - remove_wait_queue(&to_check->sleep, &wait); + finish_wait(&to_check->sleep, &wait); break; } } -- 2.53.0