diff options
author | Takashi Iwai <tiwai@suse.de> | 2016-02-09 12:02:32 +0100 |
---|---|---|
committer | Adrian Salido <salidoa@google.com> | 2017-09-21 11:51:39 -0700 |
commit | cc78a6931f7dba9d2b069300a1c3dea6d4b58cc7 (patch) | |
tree | ac9c11b8dc2098a377dffc2fb7a246414c23811e | |
parent | d39e7b145a00aef40e668586ed4ca3be43e425f8 (diff) | |
download | tegra-cc78a6931f7dba9d2b069300a1c3dea6d4b58cc7.tar.gz |
ALSA: timer: Fix race between stop and interrupt
[ Upstream commit ed8b1d6d2c741ab26d60d499d7fbb7ac801f0f51 ]
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.
Change-Id: I79e8929cb3fe9000b13ee16053fcc0467342deb0
BugLink: http://lkml.kernel.org/r/CACT4Y+Y_Bm+7epAb=8Wi=AaWd+DYS7qawX52qxdCfOfY49vozQ@mail.gmail.com
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
-rw-r--r-- | sound/core/timer.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/sound/core/timer.c b/sound/core/timer.c index 255735f16b49..d81ac4728153 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -518,9 +518,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; } |