Commit 8ee7f06f authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Greg Kroah-Hartman

alarmtimer: Prevent overflow of relative timers

commit f4781e76 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: default avatarAndrey Konovalov <andreyknvl@google.com>
Signed-off-by: default avatarThomas 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.deSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 76628325
...@@ -354,7 +354,7 @@ void alarm_start_relative(struct alarm *alarm, ktime_t start) ...@@ -354,7 +354,7 @@ void alarm_start_relative(struct alarm *alarm, ktime_t start)
{ {
struct alarm_base *base = &alarm_bases[alarm->type]; struct alarm_base *base = &alarm_bases[alarm->type];
start = ktime_add(start, base->gettime()); start = ktime_add_safe(start, base->gettime());
alarm_start(alarm, start); alarm_start(alarm, start);
} }
EXPORT_SYMBOL_GPL(alarm_start_relative); EXPORT_SYMBOL_GPL(alarm_start_relative);
...@@ -440,7 +440,7 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval) ...@@ -440,7 +440,7 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval)
overrun++; overrun++;
} }
alarm->node.expires = ktime_add(alarm->node.expires, interval); alarm->node.expires = ktime_add_safe(alarm->node.expires, interval);
return overrun; return overrun;
} }
EXPORT_SYMBOL_GPL(alarm_forward); EXPORT_SYMBOL_GPL(alarm_forward);
...@@ -630,7 +630,7 @@ static int alarm_timer_set(struct k_itimer *timr, int flags, ...@@ -630,7 +630,7 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
ktime_t now; ktime_t now;
now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime(); now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime();
exp = ktime_add(now, exp); exp = ktime_add_safe(now, exp);
} }
alarm_start(&timr->it.alarm.alarmtimer, exp); alarm_start(&timr->it.alarm.alarmtimer, exp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment