[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-35eb7258c009dc478338e674a5a84d25d0929c56@git.kernel.org>
Date: Tue, 20 Jun 2017 12:39:27 -0700
From: tip-bot for Thomas Gleixner <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: mingo@...nel.org, linux-kernel@...r.kernel.org, hpa@...or.com,
peterz@...radead.org, qiuxishi@...wei.com, tglx@...utronix.de,
john.stultz@...aro.org
Subject: [tip:timers/core] itimer: Make timeval to nsec conversion range
limited
Commit-ID: 35eb7258c009dc478338e674a5a84d25d0929c56
Gitweb: http://git.kernel.org/tip/35eb7258c009dc478338e674a5a84d25d0929c56
Author: Thomas Gleixner <tglx@...utronix.de>
AuthorDate: Tue, 20 Jun 2017 17:37:35 +0200
Committer: Thomas Gleixner <tglx@...utronix.de>
CommitDate: Tue, 20 Jun 2017 21:33:56 +0200
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@...wei.com>
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: John Stultz <john.stultz@...aro.org>
Link: http://lkml.kernel.org/r/20170620154113.505981643@linutronix.de
---
kernel/time/itimer.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
index 9dd7ff5..2ef98a0 100644
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -152,8 +152,12 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
u64 oval, nval, ointerval, ninterval;
struct cpu_itimer *it = &tsk->signal->it[clock_id];
- nval = timeval_to_ns(&value->it_value);
- ninterval = timeval_to_ns(&value->it_interval);
+ /*
+ * Use the to_ktime conversion because that clamps the maximum
+ * value to KTIME_MAX and avoid multiplication overflows.
+ */
+ nval = ktime_to_ns(timeval_to_ktime(value->it_value));
+ ninterval = ktime_to_ns(timeval_to_ktime(value->it_interval));
spin_lock_irq(&tsk->sighand->siglock);
Powered by blists - more mailing lists