提交 10632008 编写于 作者: T Thomas Gleixner

clockevents: Prevent shift out of bounds

Andrey reported that on a kernel with UBSan enabled he found:

     UBSan: Undefined behaviour in ../kernel/time/clockevents.c:75:34

     I guess it should be 1ULL here instead of 1U:
            (!ismax || evt->mult <= (1U << evt->shift)))

That's indeed the correct solution because shift might be 32.
Reported-by: NAndrey Ryabinin <a.ryabinin@samsung.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 6891c450
...@@ -72,7 +72,7 @@ static u64 cev_delta2ns(unsigned long latch, struct clock_event_device *evt, ...@@ -72,7 +72,7 @@ static u64 cev_delta2ns(unsigned long latch, struct clock_event_device *evt,
* Also omit the add if it would overflow the u64 boundary. * Also omit the add if it would overflow the u64 boundary.
*/ */
if ((~0ULL - clc > rnd) && if ((~0ULL - clc > rnd) &&
(!ismax || evt->mult <= (1U << evt->shift))) (!ismax || evt->mult <= (1ULL << evt->shift)))
clc += rnd; clc += rnd;
do_div(clc, evt->mult); do_div(clc, evt->mult);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册