Skip to content

Commit 72437e9

Browse files
colincrossRamanan Rajeswaran
authored and
Ramanan Rajeswaran
committed
timekeeping: fix 32-bit overflow in get_monotonic_boottime
get_monotonic_boottime adds three nanonsecond values stored in longs, followed by an s64. If the long values are all close to 1e9 the first three additions can overflow and become negative when added to the s64. Cast the first value to s64 so that all additions are 64 bit. Change-Id: Ic996d8b6fbef0b72f2d027b0d8ef5259b5c1a540 Signed-off-by: Colin Cross <[email protected]>
1 parent ef2f75b commit 72437e9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/time/timekeeping.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ void get_monotonic_boottime(struct timespec *ts)
10311031
} while (read_seqretry(&xtime_lock, seq));
10321032

10331033
set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec,
1034-
ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs);
1034+
(s64)ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs);
10351035
}
10361036
EXPORT_SYMBOL_GPL(get_monotonic_boottime);
10371037

0 commit comments

Comments
 (0)