Commit 960c2eab authored by Takashi Iwai's avatar Takashi Iwai Committed by Hui Tang
Browse files

ALSA: timer: Set lower bound of start tick time

stable inclusion
from stable-v5.10.219
commit bdd0aa055b8ec7e24bbc19513f3231958741d0ab
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IA6S6Y
CVE: CVE-2024-38618

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=bdd0aa055b8ec7e24bbc19513f3231958741d0ab



---------------------------

commit 4a63bd179fa8d3fcc44a0d9d71d941ddd62f0c4e upstream.

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: default avatar <syzbot+43120c2af6ca2938cc38@syzkaller.appspotmail.com>
Closes: https://lore.kernel.org/r/000000000000fa00a1061740ab6d@google.com
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20240514182745.4015-1-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
[ backport note: the error handling is changed, as the original commit
  is based on the recent cleanup with guard() in commit beb45974dd49
  -- tiwai ]
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarHui Tang <tanghui20@huawei.com>
parent f369914f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -553,6 +553,16 @@ static int snd_timer_start1(struct snd_timer_instance *timeri,
		goto unlock;
	}

	/* 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) {
			result = -EINVAL;
			goto unlock;
		}
	}

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