Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cputime: Prevent 32bit overflow in time[val|spec]_to_cputime()

The datatype __kernel_time_t is u32 on 32bit platform, so its subject to
overflows in the timeval/timespec to cputime conversion.

Currently the following functions are affected:
1. setitimer()
2. timer_create/timer_settime()
3. sys_clock_nanosleep

This can happen on MIPS32 and ARM32 with "Full dynticks CPU time accounting"
enabled, which is required for CONFIG_NO_HZ_FULL.

Enforce u64 conversion to prevent the overflow.

Fixes: 31c1fc818715 ("ARM: Kconfig: allow full nohz CPU accounting")
Signed-off-by: zengtao <prime.zeng@huawei.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Cc: <fweisbec@gmail.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1454384314-154784-1-git-send-email-prime.zeng@huawei.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

zengtao and committed by
Thomas Gleixner
0f26922f 36f90b0a

+3 -2
+3 -2
include/asm-generic/cputime_nsecs.h
··· 75 75 */ 76 76 static inline cputime_t timespec_to_cputime(const struct timespec *val) 77 77 { 78 - u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_nsec; 78 + u64 ret = (u64)val->tv_sec * NSEC_PER_SEC + val->tv_nsec; 79 79 return (__force cputime_t) ret; 80 80 } 81 81 static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val) ··· 91 91 */ 92 92 static inline cputime_t timeval_to_cputime(const struct timeval *val) 93 93 { 94 - u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_usec * NSEC_PER_USEC; 94 + u64 ret = (u64)val->tv_sec * NSEC_PER_SEC + 95 + val->tv_usec * NSEC_PER_USEC; 95 96 return (__force cputime_t) ret; 96 97 } 97 98 static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val)