Skip to content

Commit

Permalink
ALSA: timer: Set lower bound of start tick time
Browse files Browse the repository at this point in the history
Currently ALSA timer doesn't have the lower limit of the start tick
time, and it allows a very small size, e.g. 1 tick with 1ns resolution
for hrtimer.  Such a situation may lead to an unexpected RCU stall,
where  the callback repeatedly queuing the expire update, as reported
by fuzzer.

This patch introduces a sanity check of the timer start tick time, so
that the system returns an error when a too small start size is set.
As of this patch, the lower limit is hard-coded to 100us, which is
small enough but can still work somehow.

Reported-by: [email protected]
Closes: https://lore.kernel.org/r/[email protected]
Cc: <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed May 16, 2024
1 parent d731b1e commit 4a63bd1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sound/core/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ static int snd_timer_start1(struct snd_timer_instance *timeri,
SNDRV_TIMER_IFLG_START))
return -EBUSY;

/* check the actual time for the start tick;
* bail out as error if it's way too low (< 100us)
*/
if (start) {
if ((u64)snd_timer_hw_resolution(timer) * ticks < 100000)
return -EINVAL;
}

if (start)
timeri->ticks = timeri->cticks = ticks;
else if (!timeri->cticks)
Expand Down

0 comments on commit 4a63bd1

Please sign in to comment.