summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2016-02-09 12:02:32 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-02-17 12:34:37 -0800
commit71f32f598bed163d9527598014abf0344157a048 (patch)
treef92342c1785cb5efdff70414f3522b29a252f73d
parentd2bfc1530dbdc75b3b06afa8b09479d2f5d36252 (diff)
downloadlwn-71f32f598bed163d9527598014abf0344157a048.tar.gz
lwn-71f32f598bed163d9527598014abf0344157a048.zip
ALSA: timer: Fix race between stop and interrupt
commit ed8b1d6d2c741ab26d60d499d7fbb7ac801f0f51 upstream. A slave timer element also unlinks at snd_timer_stop() but it takes only slave_active_lock. When a slave is assigned to a master, however, this may become a race against the master's interrupt handling, eventually resulting in a list corruption. The actual bug could be seen with a syzkaller fuzzer test case in BugLink below. As a fix, we need to take timeri->timer->lock when timer isn't NULL, i.e. assigned to a master, while the assignment to a master itself is protected by slave_active_lock. BugLink: http://lkml.kernel.org/r/CACT4Y+Y_Bm+7epAb=8Wi=AaWd+DYS7qawX52qxdCfOfY49vozQ@mail.gmail.com Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--sound/core/timer.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/sound/core/timer.c b/sound/core/timer.c
index ef62ffbcfa8c..d90d8f4b85fe 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -508,9 +508,13 @@ static int _snd_timer_stop(struct snd_timer_instance *timeri, int event)
spin_unlock_irqrestore(&slave_active_lock, flags);
return -EBUSY;
}
+ if (timeri->timer)
+ spin_lock(&timeri->timer->lock);
timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
list_del_init(&timeri->ack_list);
list_del_init(&timeri->active_list);
+ if (timeri->timer)
+ spin_unlock(&timeri->timer->lock);
spin_unlock_irqrestore(&slave_active_lock, flags);
goto __end;
}