Skip to content

Commit 1063200

Browse files
committed
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: Andrey Ryabinin <a.ryabinin@samsung.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 6891c45 commit 1063200

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎kernel/time/clockevents.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static u64 cev_delta2ns(unsigned long latch, struct clock_event_device *evt,
7272
* Also omit the add if it would overflow the u64 boundary.
7373
*/
7474
if ((~0ULL - clc > rnd) &&
75-
(!ismax || evt->mult <= (1U << evt->shift)))
75+
(!ismax || evt->mult <= (1ULL << evt->shift)))
7676
clc += rnd;
7777

7878
do_div(clc, evt->mult);

0 commit comments

Comments
 (0)