ALSA: hrtimer: Fix stall by hrtimer_cancel()
authorTakashi Iwai <tiwai@suse.de>
Mon, 18 Jan 2016 12:52:47 +0000 (13:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 12 Mar 2016 13:25:44 +0000 (14:25 +0100)
commit206f71299754e0e8de4cef2936cbfd3bd4e6f002
tree0dec59ba3a746963651c5e9a9bda9ee18a9c31d6
parent679fc5f2dffe920466b56ae2a032338618e89239
ALSA: hrtimer: Fix stall by hrtimer_cancel()

commit 2ba1fe7a06d3624f9a7586d672b55f08f7c670f3 upstream.

hrtimer_cancel() waits for the completion from the callback, thus it
must not be called inside the callback itself.  This was already a
problem in the past with ALSA hrtimer driver, and the early commit
[fcfdebe70759: ALSA: hrtimer - Fix lock-up] tried to address it.

However, the previous fix is still insufficient: it may still cause a
lockup when the ALSA timer instance reprograms itself in its callback.
Then it invokes the start function even in snd_timer_interrupt() that
is called in hrtimer callback itself, results in a CPU stall.  This is
no hypothetical problem but actually triggered by syzkaller fuzzer.

This patch tries to fix the issue again.  Now we call
hrtimer_try_to_cancel() at both start and stop functions so that it
won't fall into a deadlock, yet giving some chance to cancel the queue
if the functions have been called outside the callback.  The proper
hrtimer_cancel() is called in anyway at closing, so this should be
enough.

Reported-and-tested-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Willy Tarreau <w@1wt.eu>
sound/core/hrtimer.c