ALSA: timer: Harden slave timer list handling 96/154896/1
authorTakashi Iwai <tiwai@suse.de>
Thu, 14 Jan 2016 15:30:58 +0000 (16:30 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 11 Oct 2017 10:48:24 +0000 (19:48 +0900)
commitcdf0aa9fbb8ec298c753e4102f05ec84124e8ba7
treebb9b75650b7244c3e96e2dc46e32665139b0e101
parent2f4f4fa5a5c5b97ad99146484af303476ff35193
ALSA: timer: Harden slave timer list handling

commit b5a663aa426f4884c71cd8580adae73f33570f0d upstream.

A slave timer instance might be still accessible in a racy way while
operating the master instance as it lacks of locking.  Since the
master operation is mostly protected with timer->lock, we should cope
with it while changing the slave instance, too.  Also, some linked
lists (active_list and ack_list) of slave instances aren't unlinked
immediately at stopping or closing, and this may lead to unexpected
accesses.

This patch tries to address these issues.  It adds spin lock of
timer->lock (either from master or slave, which is equivalent) in a
few places.  For avoiding a deadlock, we ensure that the global
slave_active_lock is always locked at first before each timer lock.

Also, ack and active_list of slave instances are properly unlinked at
snd_timer_stop() and snd_timer_close().

Last but not least, remove the superfluous call of _snd_timer_stop()
at removing slave links.  This is a noop, and calling it may confuse
readers wrt locking.  Further cleanup will follow in a later patch.

Actually we've got reports of use-after-free by syzkaller fuzzer, and
this hopefully fixes these issues.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick from linux-3.10.y to fix CVE-2016-2547 and CVE-2016-2548]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I757fd31a79a11d355bf199cf3ecb200187a18e5a
sound/core/timer.c