Merge tag 'timers_urgent_for_v5.15_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull timer fix from Borislav Petkov:

- Handle negative second values properly when converting a timespec64
to nanoseconds.

* tag 'timers_urgent_for_v5.15_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
time: Handle negative seconds correctly in timespec64_to_ns()

+7 -2
+7 -2
include/linux/time64.h
··· 25 #define TIME64_MIN (-TIME64_MAX - 1) 26 27 #define KTIME_MAX ((s64)~((u64)1 << 63)) 28 #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) 29 30 /* 31 * Limits for settimeofday(): ··· 126 */ 127 static inline s64 timespec64_to_ns(const struct timespec64 *ts) 128 { 129 - /* Prevent multiplication overflow */ 130 - if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) 131 return KTIME_MAX; 132 133 return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; 134 }
··· 25 #define TIME64_MIN (-TIME64_MAX - 1) 26 27 #define KTIME_MAX ((s64)~((u64)1 << 63)) 28 + #define KTIME_MIN (-KTIME_MAX - 1) 29 #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) 30 + #define KTIME_SEC_MIN (KTIME_MIN / NSEC_PER_SEC) 31 32 /* 33 * Limits for settimeofday(): ··· 124 */ 125 static inline s64 timespec64_to_ns(const struct timespec64 *ts) 126 { 127 + /* Prevent multiplication overflow / underflow */ 128 + if (ts->tv_sec >= KTIME_SEC_MAX) 129 return KTIME_MAX; 130 + 131 + if (ts->tv_sec <= KTIME_SEC_MIN) 132 + return KTIME_MIN; 133 134 return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; 135 }