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 05A38472767; Tue, 16 Jun 2026 17:00:57 +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=1781629258; cv=none; b=uDi1WySMB/0Bdbr1/VODdKvyEiyY+m6GS6ht1fqUy0Poovu3+Oh68tI1kwFsM0amOba/MwA55UvgNQ5CFv0as2nhp/GN37CHvzTW+9mFpgL3vgW6pU0I2IHIj1jz99wpLoXilev3hoyvCOTQp2QEwqmlQePSiHOTDG6I6wV8ZAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781629258; c=relaxed/simple; bh=pGmTxUEoVLyzvG/sDY9TIvtFt2SibNO7huQ/uZiWZfs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RiUpzfpAbWykhfbDtcvSDv8edMpqzjW6LkvwhjTdJnf3DI/LKedgCsWrx7HyDupNfp2bRW+ecZDDrCAZ5ZMmTIC3f1kDncf9kobaEyEXeriTlhyLJ7hpknCOq2bfUt4BivyoevXnEcwQsuRFgH+O7vrF7f7BONoX2Z02RZ80Yr4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Jgw5+OJW; 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="Jgw5+OJW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F36CE1F000E9; Tue, 16 Jun 2026 17:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781629256; bh=S2JVxdp16cuH4GrQ6FM+aa7b4DCuv9qVpL4Hqs+fYPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Jgw5+OJWQH/qGHsdgEa8eXVl/pHLxj33xUGYS5kbfggzA13ahaQ8x727RMuw9yEXT zti4d/x2sGLEF0IfU6gRJ0a3KjLmCRsIQ8v0dq/wQhb6CphZN2G27TmbclpfLX3vJA 6xKR2SQ8G2DB0GbKut8gl2ZG3BtrULZfnZ+/UmqU= 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.6 250/452] ALSA: PCM: Fix wait queue list corruption in snd_pcm_drain() on linked streams Date: Tue, 16 Jun 2026 20:27:57 +0530 Message-ID: <20260616145130.795001513@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145117.796205997@linuxfoundation.org> References: <20260616145117.796205997@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.6-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 214210c8747458..c1b7ee1f3e7463 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2180,9 +2180,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; @@ -2200,7 +2199,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