]> Git Repo - linux.git/commitdiff
clockevents: Prevent shift out of bounds
authorThomas Gleixner <[email protected]>
Mon, 20 Oct 2014 11:07:50 +0000 (15:07 +0400)
committerThomas Gleixner <[email protected]>
Sat, 25 Oct 2014 08:43:15 +0000 (10:43 +0200)
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 <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
kernel/time/clockevents.c

index 9c94c19f13052fb45391584cf14216f2eb494825..55449909f11475372135ac61b33e65114eb151ba 100644 (file)
@@ -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.
         */
        if ((~0ULL - clc > rnd) &&
-           (!ismax || evt->mult <= (1U << evt->shift)))
+           (!ismax || evt->mult <= (1ULL << evt->shift)))
                clc += rnd;
 
        do_div(clc, evt->mult);
This page took 0.056176 seconds and 4 git commands to generate.