ALSA: seq: Make ioctls race-free
authorTakashi Iwai <tiwai@suse.de>
Tue, 9 Jan 2018 22:11:03 +0000 (23:11 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 13 Feb 2018 18:32:22 +0000 (18:32 +0000)
commitd6693160906d55ba376bf0b88b7c129762170162
treeff412d6875c74844b19b775846a6b3b78e9b7130
parent57e49cc5d8048f4274b3b2c8ec075f656f8a3ed1
ALSA: seq: Make ioctls race-free

commit b3defb791b26ea0683a93a4f49c77ec45ec96f10 upstream.

The ALSA sequencer ioctls have no protection against racy calls while
the concurrent operations may lead to interfere with each other.  As
reported recently, for example, the concurrent calls of setting client
pool with a combination of write calls may lead to either the
unkillable dead-lock or UAF.

As a slightly big hammer solution, this patch introduces the mutex to
make each ioctl exclusive.  Although this may reduce performance via
parallel ioctl calls, usually it's not demanded for sequencer usages,
hence it should be negligible.

Reported-by: Luo Quan <a4651386@163.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
[bwh: Backported to 3.2: ioctl dispatch is done from snd_seq_do_ioctl();
 take the mutex and add ret variable there.]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
sound/core/seq/seq_clientmgr.c
sound/core/seq/seq_clientmgr.h