Patch "ALSA: seq: Fix racy cell insertions during snd_seq_pool_done()" has been added to the 4.10-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
ALSA: seq: Fix racy cell insertions during snd_seq_pool_done()
to the 4.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
alsa-seq-fix-racy-cell-insertions-during-snd_seq_pool_done.patch
and it can be found in the queue-4.10 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
c520ff3d03f0b5db7146d9beed6373ad5d2a5e0eMon Sep 17 00:00:00 2001
From: Takashi Iwai <[email protected]>
Date: Tue, 21 Mar 2017 13:56:04 +0100
Subject: ALSA: seq: Fix racy cell insertions during snd_seq_pool_done()
From: Takashi Iwai <[email protected]>
commit c520ff3d03f0b5db7146d9beed6373ad5d2a5e0e upstream.
When snd_seq_pool_done() is called, it marks the closing flag to refuse the further cell insertions. But snd_seq_pool_done() itself doesn't clear the cells but just waits until all cells are cleared by the caller side. That is, it's racy, and this leads to the endless stall as syzkaller spotted.
This patch addresses the racy by splitting the setup of pool->closing flag out of snd_seq_pool_done(), and calling it properly before snd_seq_pool_done().
--- sound/core/seq/seq_clientmgr.c | 1 + sound/core/seq/seq_fifo.c | 3 +++ sound/core/seq/seq_memory.c | 17 +++++++++++++---- sound/core/seq/seq_memory.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-)
sound/core/seq/seq_clientmgr.c +1 -0
@@ -1832,6 +1832,7 @@ static int snd_seq_ioctl_set_client_pool info->output_pool != client->pool->size)) {if (snd_seq_write_pool_allocated (client)) {/* remove all existing cells */ +snd_seq_pool_mark_closing (client->pool);snd_seq_queue_client_leave_cells (client->number);snd_seq_pool_done (client->pool); }
sound/core/seq/seq_fifo.c +3 -0
@@ -70,6 +70,9 @@ void snd_seq_fifo_delete(struct snd_seq_return ; *fifo =NULL ; +if (f->pool) +snd_seq_pool_mark_closing (f->pool); +snd_seq_fifo_clear (f);/* wake up clients if any */
sound/core/seq/seq_memory.c +13 -4
@@ -414,6 +414,18 @@ int snd_seq_pool_init(struct snd_seq_pooreturn 0 ; } +/* refuse the further insertion to the pool */ +void snd_seq_pool_mark_closing (struct snd_seq_pool *pool) +{ +unsigned long flags; + +if (snd_BUG_ON (!pool)) +return ; +spin_lock_irqsave (&pool->lock, flags); + pool->closing =1 ; +spin_unlock_irqrestore (&pool->lock, flags); +} +/* remove events */ int snd_seq_pool_done (struct snd_seq_pool *pool) {
@@ -424,10 +436,6 @@ int snd_seq_pool_done(struct snd_seq_pooreturn -EINVAL ;/* wait for closing all threads */ -spin_lock_irqsave (&pool->lock, flags); - pool->closing =1 ; -spin_unlock_irqrestore (&pool->lock, flags); -if (waitqueue_active (&pool->output_sleep))wake_up (&pool->output_sleep);
@@ -484,6 +492,7 @@ int snd_seq_pool_delete(struct snd_seq_p *ppool =NULL ;if (pool ==NULL )return 0 ; +snd_seq_pool_mark_closing (pool);snd_seq_pool_done (pool);kfree (pool);return 0 ;
sound/core/seq/seq_memory.h +1 -0
@@ -84,6 +84,7 @@ static inline int snd_seq_total_cells(stint snd_seq_pool_init (struct snd_seq_pool *pool);/* done pool - free events */ +void snd_seq_pool_mark_closing (struct snd_seq_pool *pool);int snd_seq_pool_done (struct snd_seq_pool *pool);/* create pool */
Patches currently in stable-queue which might be from [email protected] are
queue-4.10/alsa-ctxfi-fix-the-incorrect-check-of-dma_set_mask-call.patch queue-4.10/alsa-hda-adding-a-group-of-pin-definition-to-fix-headset-problem.patch queue-4.10/alsa-seq-fix-racy-cell-insertions-during-snd_seq_pool_done.patch