From: tip-bot for Thomas Gleixner <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com,
peterz@infradead.org, qiuxishi@huawei.com, tglx@linutronix.de,
john.stultz@linaro.org
Subject: [tip:timers/core] itimer: Make timeval to nsec conversion range limited
Date: Tue, 20 Jun 2017 12:39:27 -0700 [thread overview]
Message-ID: <tip-35eb7258c009dc478338e674a5a84d25d0929c56@git.kernel.org> (raw)
In-Reply-To: <20170620154113.505981643@linutronix.de>
Commit-ID: 35eb7258c009dc478338e674a5a84d25d0929c56
Gitweb: http://git.kernel.org/tip/35eb7258c009dc478338e674a5a84d25d0929c56
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 20 Jun 2017 17:37:35 +0200
Committer: Thomas Gleixner <tglx@linutronix.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@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
---
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);
next prev parent reply other threads:[~2017-06-20 19:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-20 15:37 [patch 0/2] timers: Prevent multiplication overflow in timespec/val conversions Thomas Gleixner
2017-06-20 15:37 ` [patch 1/2] itimer: Make timeval to nsec conversion range limited Thomas Gleixner
2017-06-20 19:39 ` tip-bot for Thomas Gleixner [this message]
2017-06-20 15:37 ` [patch 2/2] posix-cpu-timers: Make timespec to nsec conversion safe Thomas Gleixner
2017-06-20 19:40 ` [tip:timers/core] " tip-bot for Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-35eb7258c009dc478338e674a5a84d25d0929c56@git.kernel.org \
--to=tipbot@zytor.com \
--cc=hpa@zytor.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=qiuxishi@huawei.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome