From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbdFTPly (ORCPT ); Tue, 20 Jun 2017 11:41:54 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:44940 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916AbdFTPlv (ORCPT ); Tue, 20 Jun 2017 11:41:51 -0400 Message-Id: <20170620154113.505981643@linutronix.de> User-Agent: quilt/0.63-1 Date: Tue, 20 Jun 2017 17:37:35 +0200 From: Thomas Gleixner To: LKML Cc: John Stultz , Peter Zijlstra , Xishi Qiu Subject: [patch 1/2] itimer: Make timeval to nsec conversion range limited References: <20170620153734.970526461@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=itimer--Make-timeval-to-nsec-conversion-range-limited.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Thomas Gleixner --- kernel/time/itimer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) Signed-off-by: Thomas Gleixner --- 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);