]> git.karo-electronics.de Git - karo-tx-linux.git/commit
ktime_add_ns() may overflow on 32bit architectures
authorDavid Engraf <david.engraf@sysgo.com>
Tue, 26 Mar 2013 23:24:11 +0000 (10:24 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 2 Apr 2013 07:28:54 +0000 (18:28 +1100)
commit4a4910c0e35a91e49983061f04122082775629f2
tree0da89d3036ed1ff7bf786194a302e61523f5307e
parentbc6d3d60d78993bea51e20ea8dc2eef4dbdba46e
ktime_add_ns() may overflow on 32bit architectures

I've triggered an overflow when using ktime_add_ns() on a 32bit
architecture not supporting CONFIG_KTIME_SCALAR.

When passing a very high value for u64 nsec, e.g.  7881299347898368000 the
do_div() function converts this value to seconds (7881299347) which is
still to high to pass to the ktime_set() function as long.  The result in
my case is a negative value.

The problem on my system occurs in the tick-sched.c,
tick_nohz_stop_sched_tick() when time_delta is set to
timekeeping_max_deferment().  The check for time_delta < KTIME_MAX is
valid, thus ktime_add_ns() is called with a too large value resulting in a
negative expire value.  This leads to an endless loop in the ticker code:

time_delta: 7881299347898368000
expires = ktime_add_ns(last_update, time_delta)
expires: negative value

This error doesn't occurs on 64bit or architectures supporting
CONFIG_KTIME_SCALAR (e.g.  ARM, x86-32).  64-bit arches doesn't run into
this problem because ktime_add_ns() can directly calculate the result
without calling do_div() and ktime_set().

Signed-off-by: David Engraf <david.engraf@sysgo.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/hrtimer.c