Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1670890

[patch 1/2] itimer: Make timeval to nsec conversion range limited

From Thomas Gleixner <tglx@linutronix.de>
Newsgroups linux.kernel
Subject [patch 1/2] itimer: Make timeval to nsec conversion range limited
Date 2017-06-20 17:50 +0200
Message-ID <tUtzI-238-23@gated-at.bofh.it> (permalink)
References <tUtzH-238-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 kernel/time/itimer.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)


Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/itimer.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -138,8 +138,12 @@ static void set_cpu_itimer(struct task_s
 	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);
 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[patch 0/2] timers: Prevent multiplication overflow in timespec/val  conversions Thomas Gleixner <tglx@linutronix.de> - 2017-06-20 17:50 +0200
  [patch 1/2] itimer: Make timeval to nsec conversion range limited Thomas Gleixner <tglx@linutronix.de> - 2017-06-20 17:50 +0200
    [tip:timers/core] itimer: Make timeval to nsec conversion range  limited tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2017-06-20 21:50 +0200
  [patch 2/2] posix-cpu-timers: Make timespec to nsec conversion safe Thomas Gleixner <tglx@linutronix.de> - 2017-06-20 17:50 +0200
    [tip:timers/core] posix-cpu-timers: Make timespec to nsec  conversion safe tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2017-06-20 21:50 +0200

csiph-web