diff options
author | Takashi Iwai <tiwai@suse.de> | 2016-09-07 09:45:31 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2016-09-08 04:45:05 -0400 |
commit | 9f8a7658bcafb2a7853f7a2eae8a94e87e6e695b (patch) | |
tree | 73f43bb689b5b319d22e43909eff5cb5277bea77 /sound/core | |
parent | 11749e086b2766cccf6217a527ef5c5604ba069c (diff) |
ALSA: timer: Fix zero-division by continue of uninitialized instance
When a user timer instance is continued without the explicit start
beforehand, the system gets eventually zero-division error like:
divide error: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN
CPU: 1 PID: 27320 Comm: syz-executor Not tainted 4.8.0-rc3-next-20160825+ #8
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
task: ffff88003c9b2280 task.stack: ffff880027280000
RIP: 0010:[<ffffffff858e1a6c>] [< inline >] ktime_divns include/linux/ktime.h:195
RIP: 0010:[<ffffffff858e1a6c>] [<ffffffff858e1a6c>] snd_hrtimer_callback+0x1bc/0x3c0 sound/core/hrtimer.c:62
Call Trace:
<IRQ>
[< inline >] __run_hrtimer kernel/time/hrtimer.c:1238
[<ffffffff81504335>] __hrtimer_run_queues+0x325/0xe70 kernel/time/hrtimer.c:1302
[<ffffffff81506ceb>] hrtimer_interrupt+0x18b/0x420 kernel/time/hrtimer.c:1336
[<ffffffff8126d8df>] local_apic_timer_interrupt+0x6f/0xe0 arch/x86/kernel/apic/apic.c:933
[<ffffffff86e13056>] smp_apic_timer_interrupt+0x76/0xa0 arch/x86/kernel/apic/apic.c:957
[<ffffffff86e1210c>] apic_timer_interrupt+0x8c/0xa0 arch/x86/entry/entry_64.S:487
<EOI>
.....
Although a similar issue was spotted and a fix patch was merged in
commit [6b760bb2c63a: ALSA: timer: fix division by zero after
SNDRV_TIMER_IOCTL_CONTINUE], it seems covering only a part of
iceberg.
In this patch, we fix the issue a bit more drastically. Basically the
continue of an uninitialized timer is supposed to be a fresh start, so
we do it for user timers. For the direct snd_timer_continue() call,
there is no way to pass the initial tick value, so we kick out for the
uninitialized case.
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/timer.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sound/core/timer.c b/sound/core/timer.c index 2706061fc1ea..fc144f43faa6 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c | |||
@@ -35,6 +35,9 @@ | |||
35 | #include <sound/initval.h> | 35 | #include <sound/initval.h> |
36 | #include <linux/kmod.h> | 36 | #include <linux/kmod.h> |
37 | 37 | ||
38 | /* internal flags */ | ||
39 | #define SNDRV_TIMER_IFLG_PAUSED 0x00010000 | ||
40 | |||
38 | #if IS_ENABLED(CONFIG_SND_HRTIMER) | 41 | #if IS_ENABLED(CONFIG_SND_HRTIMER) |
39 | #define DEFAULT_TIMER_LIMIT 4 | 42 | #define DEFAULT_TIMER_LIMIT 4 |
40 | #else | 43 | #else |
@@ -539,6 +542,10 @@ static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop) | |||
539 | } | 542 | } |
540 | } | 543 | } |
541 | timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START); | 544 | timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START); |
545 | if (stop) | ||
546 | timeri->flags &= ~SNDRV_TIMER_IFLG_PAUSED; | ||
547 | else | ||
548 | timeri->flags |= SNDRV_TIMER_IFLG_PAUSED; | ||
542 | snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : | 549 | snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : |
543 | SNDRV_TIMER_EVENT_CONTINUE); | 550 | SNDRV_TIMER_EVENT_CONTINUE); |
544 | unlock: | 551 | unlock: |
@@ -600,6 +607,10 @@ int snd_timer_stop(struct snd_timer_instance *timeri) | |||
600 | */ | 607 | */ |
601 | int snd_timer_continue(struct snd_timer_instance *timeri) | 608 | int snd_timer_continue(struct snd_timer_instance *timeri) |
602 | { | 609 | { |
610 | /* timer can continue only after pause */ | ||
611 | if (!(timeri->flags & SNDRV_TIMER_IFLG_PAUSED)) | ||
612 | return -EINVAL; | ||
613 | |||
603 | if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) | 614 | if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) |
604 | return snd_timer_start_slave(timeri, false); | 615 | return snd_timer_start_slave(timeri, false); |
605 | else | 616 | else |
@@ -1831,6 +1842,9 @@ static int snd_timer_user_continue(struct file *file) | |||
1831 | tu = file->private_data; | 1842 | tu = file->private_data; |
1832 | if (!tu->timeri) | 1843 | if (!tu->timeri) |
1833 | return -EBADFD; | 1844 | return -EBADFD; |
1845 | /* start timer instead of continue if it's not used before */ | ||
1846 | if (!(tu->timeri->flags & SNDRV_TIMER_IFLG_PAUSED)) | ||
1847 | return snd_timer_user_start(file); | ||
1834 | tu->timeri->lost = 0; | 1848 | tu->timeri->lost = 0; |
1835 | return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0; | 1849 | return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0; |
1836 | } | 1850 | } |