Skip to content

Commit

Permalink
time: Avoid potential shift overflow with large shift values
Browse files Browse the repository at this point in the history
Andreas Schwab noticed that the 1 << tk->shift could overflow if the
shift value was greater than 30, since 1 would be a 32bit long on
32bit architectures. This issue was introduced by 1e75fa8 (time:
Condense timekeeper.xtime into xtime_sec)

Use 1ULL instead to ensure we don't overflow on the shift.

Reported-by: Andreas Schwab <[email protected]>
Signed-off-by: John Stultz <[email protected]>
Cc: Prarit Bhargava <[email protected]>
Cc: Ingo Molnar <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
  • Loading branch information
johnstultz-work authored and KAGA-KOKO committed Aug 22, 2012
1 parent 85dc8f0 commit 6ea565a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,9 @@ static void update_wall_time(void)
* the vsyscall implementations are converted to use xtime_nsec
* (shifted nanoseconds), this can be killed.
*/
remainder = tk->xtime_nsec & ((1 << tk->shift) - 1);
remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1);
tk->xtime_nsec -= remainder;
tk->xtime_nsec += 1 << tk->shift;
tk->xtime_nsec += 1ULL << tk->shift;
tk->ntp_error += remainder << tk->ntp_error_shift;

/*
Expand Down

0 comments on commit 6ea565a

Please sign in to comment.