ALSA: timer: Limit max instances per timer
authorTakashi Iwai <tiwai@suse.de>
Sun, 5 Nov 2017 09:07:43 +0000 (10:07 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 1 Jan 2018 20:51:02 +0000 (20:51 +0000)
commit57a70fe807328d99a7e483592b883b2e8abaca13
tree1e604612c2d10da9aeb9368075aa2c144af5b4ff
parenta6a1f3005929d1a7ed35d683ba4ce2a12aad7395
ALSA: timer: Limit max instances per timer

commit 9b7d869ee5a77ed4a462372bb89af622e705bfb8 upstream.

Currently we allow unlimited number of timer instances, and it may
bring the system hogging way too much CPU when too many timer
instances are opened and processed concurrently.  This may end up with
a soft-lockup report as triggered by syzkaller, especially when
hrtimer backend is deployed.

Since such insane number of instances aren't demanded by the normal
use case of ALSA sequencer and it merely  opens a risk only for abuse,
this patch introduces the upper limit for the number of instances per
timer backend.  As default, it's set to 1000, but for the fine-grained
timer like hrtimer, it's set to 100.

Reported-by: syzbot
Tested-by: Jérôme Glisse <jglisse@redhat.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
include/sound/timer.h
sound/core/hrtimer.c
sound/core/timer.c