Skip to content

Commit aac7fa2

Browse files
KAGA-KOKOgregkh
authored andcommitted
alarmtimer: Prevent overflow of relative timers
commit f4781e76f90df7aec400635d73ea4c35ee1d4765 upstream. Andrey reported a alartimer related RCU stall while fuzzing the kernel with syzkaller. The reason for this is an overflow in ktime_add() which brings the resulting time into negative space and causes immediate expiry of the timer. The following rearm with a small interval does not bring the timer back into positive space due to the same issue. This results in a permanent firing alarmtimer which hogs the CPU. Use ktime_add_safe() instead which detects the overflow and clamps the result to KTIME_SEC_MAX. Reported-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Kostya Serebryany <kcc@google.com> Cc: syzkaller <syzkaller@googlegroups.com> Cc: John Stultz <john.stultz@linaro.org> Cc: Dmitry Vyukov <dvyukov@google.com> Link: http://lkml.kernel.org/r/20170530211655.802921648@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4d4d501 commit aac7fa2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/time/alarmtimer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void alarm_start_relative(struct alarm *alarm, ktime_t start)
339339
{
340340
struct alarm_base *base = &alarm_bases[alarm->type];
341341

342-
start = ktime_add(start, base->gettime());
342+
start = ktime_add_safe(start, base->gettime());
343343
alarm_start(alarm, start);
344344
}
345345
EXPORT_SYMBOL_GPL(alarm_start_relative);
@@ -425,7 +425,7 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval)
425425
overrun++;
426426
}
427427

428-
alarm->node.expires = ktime_add(alarm->node.expires, interval);
428+
alarm->node.expires = ktime_add_safe(alarm->node.expires, interval);
429429
return overrun;
430430
}
431431
EXPORT_SYMBOL_GPL(alarm_forward);
@@ -617,7 +617,7 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
617617
ktime_t now;
618618

619619
now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime();
620-
exp = ktime_add(now, exp);
620+
exp = ktime_add_safe(now, exp);
621621
}
622622

623623
alarm_start(&timr->it.alarm.alarmtimer, exp);

0 commit comments

Comments
 (0)