]> git.ipfire.org Git - thirdparty/linux.git/commit
ALSA: PCM: Fix wait queue list corruption in snd_pcm_drain() on linked streams
authorJi'an Zhou <eilaimemedsnaimel@gmail.com>
Thu, 4 Jun 2026 14:25:59 +0000 (14:25 +0000)
committerTakashi Iwai <tiwai@suse.de>
Thu, 4 Jun 2026 15:24:26 +0000 (17:24 +0200)
commit88fe2e3658726cb21ff2dcf9770bf672f9b9d31b
treec42310a7be73cf7083633816e2b22d0c8bba6ffc
parentb734412619821f3ed63ba63533f539672cb7a76d
ALSA: PCM: Fix wait queue list corruption in snd_pcm_drain() on linked streams

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 <eilaimemedsnaimel@gmail.com>
Link: https://patch.msgid.link/20260604142559.3840881-1-eilaimemedsnaimel@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_native.c