Vegard Nossum
08b1cf4964
time: Avoid undefined behaviour in ktime_add_safe()
commit 979515c564 upstream.
I ran into this:
================================================================================
UBSAN: Undefined behaviour in kernel/time/hrtimer.c:310:16
signed integer overflow:
9223372036854775807 + 50000 cannot be represented in type 'long long int'
CPU: 2 PID: 4798 Comm: trinity-c2 Not tainted 4.8.0-rc1+ #91
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
0000000000000000 ffff88010ce6fb88 ffffffff82344740 0000000041b58ab3
ffffffff84f97a20 ffffffff82344694 ffff88010ce6fbb0 ffff88010ce6fb60
000000000000c350 ffff88010ce6f968 dffffc0000000000 ffffffff857bc320
Call Trace:
[<ffffffff82344740>] dump_stack+0xac/0xfc
[<ffffffff82344694>] ? _atomic_dec_and_lock+0xc4/0xc4
[<ffffffff8242df78>] ubsan_epilogue+0xd/0x8a
[<ffffffff8242e6b4>] handle_overflow+0x202/0x23d
[<ffffffff8242e4b2>] ? val_to_string.constprop.6+0x11e/0x11e
[<ffffffff8236df71>] ? timerqueue_add+0x151/0x410
[<ffffffff81485c48>] ? hrtimer_start_range_ns+0x3b8/0x1380
[<ffffffff81795631>] ? memset+0x31/0x40
[<ffffffff8242e6fd>] __ubsan_handle_add_overflow+0xe/0x10
[<ffffffff81488ac9>] hrtimer_nanosleep+0x5d9/0x790
[<ffffffff814884f0>] ? hrtimer_init_sleeper+0x80/0x80
[<ffffffff813a9ffb>] ? __might_sleep+0x5b/0x260
[<ffffffff8148be10>] common_nsleep+0x20/0x30
[<ffffffff814906c7>] SyS_clock_nanosleep+0x197/0x210
[<ffffffff81490530>] ? SyS_clock_getres+0x150/0x150
[<ffffffff823c7113>] ? __this_cpu_preempt_check+0x13/0x20
[<ffffffff8162ef60>] ? __context_tracking_exit.part.3+0x30/0x1b0
[<ffffffff81490530>] ? SyS_clock_getres+0x150/0x150
[<ffffffff81007bd3>] do_syscall_64+0x1b3/0x4b0
[<ffffffff845f85aa>] entry_SYSCALL64_slow_path+0x25/0x25
================================================================================
Add a new ktime_add_unsafe() helper which doesn't check for overflow, but
doesn't throw a UBSAN warning when it does overflow either.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-01-31 12:06:08 +01:00
..
2017-02-18 16:39:26 +01:00
2017-03-15 09:57:15 +08:00
2017-10-12 11:27:34 +02:00
2016-10-28 03:01:34 -04:00
2017-03-15 09:57:14 +08:00
2016-10-16 17:36:14 +02:00
2017-12-20 10:04:56 +01:00
2017-10-08 10:14:19 +02:00
2017-05-08 07:46:01 +02:00
2017-10-05 09:41:47 +02:00
2017-02-01 08:30:53 +01:00
2017-11-15 17:13:11 +01:00
2017-10-08 10:14:18 +02:00
2018-01-17 09:35:31 +01:00
2017-12-09 18:42:43 +01:00
2017-01-12 11:22:50 +01:00
2017-06-14 13:16:23 +02:00
2016-12-08 07:15:24 +01:00
2017-07-05 14:37:20 +02:00
2018-01-17 09:35:33 +01:00
2017-02-14 15:22:51 -08:00
2017-10-12 11:27:35 +02:00
2018-01-10 09:27:10 +01:00
2017-08-06 19:19:42 -07:00
2017-03-22 12:04:15 +01:00
2016-10-28 03:01:26 -04:00
2017-07-21 07:44:58 +02:00
2017-05-14 13:32:59 +02:00
2017-07-15 11:57:44 +02:00
2018-01-17 09:35:30 +01:00
2017-06-14 13:16:24 +02:00
2017-06-17 06:39:36 +02:00
2018-01-10 09:27:10 +01:00
2016-09-30 10:18:37 +02:00
2017-08-06 19:19:42 -07:00
2017-12-16 10:33:54 +01:00
2017-05-14 13:32:59 +02:00
2017-06-07 12:05:59 +02:00
2017-03-12 06:37:25 +01:00
2018-01-02 20:33:25 +01:00
2016-09-24 10:07:43 +02:00
2017-01-19 20:17:19 +01:00
2018-01-05 15:44:26 +01:00
2018-01-23 19:50:12 +01:00
2016-10-28 03:01:30 -04:00
2017-10-27 10:23:18 +02:00
2017-05-25 14:30:17 +02:00
2018-01-31 12:06:08 +01:00
2017-04-08 09:53:32 +02:00
2017-03-18 19:09:58 +08:00
2017-09-02 07:06:51 +02:00
2017-07-21 07:44:56 +02:00
2017-06-17 06:39:36 +02:00
2017-10-27 10:23:17 +02:00
2017-06-14 13:16:26 +02:00
2017-02-09 08:02:47 +01:00
2017-08-11 09:08:50 -07:00
2017-06-26 07:13:11 +02:00
2017-12-20 10:04:59 +01:00
2017-12-25 14:22:09 +01:00
2017-12-16 10:33:50 +01:00
2018-01-05 15:44:24 +01:00
2017-04-30 05:49:28 +02:00
2016-11-15 07:46:37 +01:00
2016-11-15 07:46:37 +01:00
2017-11-18 11:11:05 +01:00
2017-12-05 11:22:49 +01:00
2017-02-01 08:30:53 +01:00
2016-10-07 15:23:41 +02:00
2017-12-16 10:33:51 +01:00
2017-11-24 08:32:25 +01:00
2016-09-30 10:18:37 +02:00
2017-09-13 14:09:45 -07:00
2016-12-08 07:15:24 +01:00
2018-01-05 15:44:26 +01:00
2017-02-09 08:02:46 +01:00
2017-11-21 09:21:22 +01:00
2018-01-17 09:35:29 +01:00
2017-08-24 17:02:36 -07:00
2016-10-31 04:13:58 -06:00
2017-11-15 17:13:11 +01:00
2017-08-06 19:19:43 -07:00
2017-06-14 13:16:20 +02:00
2016-11-10 16:36:37 +01:00
2017-06-14 13:16:23 +02:00
2018-01-31 12:06:07 +01:00
2016-10-28 03:01:32 -04:00
2017-08-06 19:19:42 -07:00
2018-01-17 09:35:29 +01:00
2017-11-24 08:32:24 +01:00
2017-08-11 09:08:58 -07:00
2016-09-30 10:18:37 +02:00
2016-10-28 03:01:30 -04:00
2016-10-28 03:01:34 -04:00
2016-10-07 15:23:46 +02:00
2017-12-16 10:33:48 +01:00
2017-02-04 09:45:08 +01:00
2017-06-29 12:48:51 +02:00
2017-10-21 17:09:02 +02:00
2017-09-27 11:00:13 +02:00
2016-12-10 19:07:25 +01:00
2017-12-09 18:42:43 +01:00
2018-01-23 19:50:15 +01:00
2017-07-27 15:06:07 -07:00
2018-01-02 20:33:28 +01:00
2017-09-13 14:09:45 -07:00