Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: seq: Improve data consistency at polling

snd_seq_poll() calls snd_seq_write_pool_allocated() that reads out a
field in client->pool object, while it can be updated concurrently via
ioctls, as reported by syzbot. The data race itself is harmless, as
it's merely a poll() call, and the state is volatile. OTOH, the read
out of poll object info from the caller side is fragile, and we can
leave it better in snd_seq_pool_poll_wait() alone.

A similar pattern is seen in snd_seq_kernel_client_write_poll(), too,
which is called from the OSS sequencer.

This patch drops the pool checks from the caller side and add the
pool->lock in snd_seq_pool_poll_wait() for better data consistency.

Reported-by: syzbot+2d373c9936c00d7e120c@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/67c88903.050a0220.15b4b9.0028.GAE@google.com
Link: https://patch.msgid.link/20250307084246.29271-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+2 -4
+1 -4
sound/core/seq/seq_clientmgr.c
··· 1130 1130 if (snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT) { 1131 1131 1132 1132 /* check if data is available in the pool */ 1133 - if (!snd_seq_write_pool_allocated(client) || 1134 - snd_seq_pool_poll_wait(client->pool, file, wait)) 1133 + if (snd_seq_pool_poll_wait(client->pool, file, wait)) 1135 1134 mask |= EPOLLOUT | EPOLLWRNORM; 1136 1135 } 1137 1136 ··· 2565 2566 if (client == NULL) 2566 2567 return -ENXIO; 2567 2568 2568 - if (! snd_seq_write_pool_allocated(client)) 2569 - return 1; 2570 2569 if (snd_seq_pool_poll_wait(client->pool, file, wait)) 2571 2570 return 1; 2572 2571 return 0;
+1
sound/core/seq/seq_memory.c
··· 427 427 poll_table *wait) 428 428 { 429 429 poll_wait(file, &pool->output_sleep, wait); 430 + guard(spinlock_irq)(&pool->lock); 430 431 return snd_seq_output_ok(pool); 431 432 } 432 433