]> Pileus Git - ~andy/linux/blobdiff - kernel/hrtimer.c
hrtimer: Fix ktime_add_ns() overflow on 32bit architectures
[~andy/linux] / kernel / hrtimer.c
index 071e093c448670024d3804a7b8e03c4eff2eb68f..c0875ae0de1791239fdc6fadcc1a7f6c8ab09729 100644 (file)
@@ -286,6 +286,10 @@ ktime_t ktime_add_ns(const ktime_t kt, u64 nsec)
        } else {
                unsigned long rem = do_div(nsec, NSEC_PER_SEC);
 
+               /* Make sure nsec fits into long */
+               if (unlikely(nsec > KTIME_SEC_MAX))
+                       return (ktime_t){ .tv64 = KTIME_MAX };
+
                tmp = ktime_set((long)nsec, rem);
        }