Skip to content

Commit acd4780

Browse files
tiwaiopsiff
authored andcommitted
ALSA: seq: Improve data consistency at polling
[ Upstream commit e3cd33a ] 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: [email protected] Closes: https://lore.kernel.org/[email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 8c1a16d612ef7f824b87f1a54f5de1f5a6e870ab)
1 parent f368d34 commit acd4780

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

sound/core/seq/seq_clientmgr.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ static __poll_t snd_seq_poll(struct file *file, poll_table * wait)
11691169
if (snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT) {
11701170

11711171
/* check if data is available in the pool */
1172-
if (!snd_seq_write_pool_allocated(client) ||
1173-
snd_seq_pool_poll_wait(client->pool, file, wait))
1172+
if (snd_seq_pool_poll_wait(client->pool, file, wait))
11741173
mask |= EPOLLOUT | EPOLLWRNORM;
11751174
}
11761175

@@ -2584,8 +2583,6 @@ int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_table
25842583
if (client == NULL)
25852584
return -ENXIO;
25862585

2587-
if (! snd_seq_write_pool_allocated(client))
2588-
return 1;
25892586
if (snd_seq_pool_poll_wait(client->pool, file, wait))
25902587
return 1;
25912588
return 0;

sound/core/seq/seq_memory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file,
429429
poll_table *wait)
430430
{
431431
poll_wait(file, &pool->output_sleep, wait);
432+
guard(spinlock_irq)(&pool->lock);
432433
return snd_seq_output_ok(pool);
433434
}
434435

0 commit comments

Comments
 (0)