Skip to content

Commit 35eb725

Browse files
committed
itimer: Make timeval to nsec conversion range limited
The expiry time of a itimer is supplied through sys_setitimer() via a struct timeval. The timeval is validated for correctness. In the actual set timer implementation the timeval is converted to a scalar nanoseconds value. If the tv_sec part of the time spec is large enough the conversion to nanoseconds (sec * NSEC_PER_SEC) overflows 64bit. Mitigate that by using the timeval_to_ktime() conversion function, which checks the tv_sec part for a potential mult overflow and clamps the result to KTIME_MAX, which is about 292 years. Reported-by: Xishi Qiu <qiuxishi@huawei.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: John Stultz <john.stultz@linaro.org> Link: http://lkml.kernel.org/r/20170620154113.505981643@linutronix.de
1 parent d15bc69 commit 35eb725

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎kernel/time/itimer.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,12 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
152152
u64 oval, nval, ointerval, ninterval;
153153
struct cpu_itimer *it = &tsk->signal->it[clock_id];
154154

155-
nval = timeval_to_ns(&value->it_value);
156-
ninterval = timeval_to_ns(&value->it_interval);
155+
/*
156+
* Use the to_ktime conversion because that clamps the maximum
157+
* value to KTIME_MAX and avoid multiplication overflows.
158+
*/
159+
nval = ktime_to_ns(timeval_to_ktime(value->it_value));
160+
ninterval = ktime_to_ns(timeval_to_ktime(value->it_interval));
157161

158162
spin_lock_irq(&tsk->sighand->siglock);
159163

0 commit comments

Comments
 (0)