aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSasha Levin <sasha.levin@oracle.com>2014-12-03 19:22:48 -0500
committerJohn Stultz <john.stultz@linaro.org>2015-01-07 12:49:14 -0500
commit6ada1fc0e1c4775de0e043e1bd3ae9d065491aa5 (patch)
treeb6a02726aa5f93ccb61e7161c7705590424f7830 /include
parentb2776bf7149bddd1f4161f14f79520f17fc1d71d (diff)
time: settimeofday: Validate the values of tv from user
An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: stable <stable@vger.kernel.org> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> [jstultz: include trivial milisecond->microsecond correction noticed by Andy] Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/time.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/time.h b/include/linux/time.h
index 8c42cf8d2444..5989b0ead1ec 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -99,6 +99,19 @@ static inline bool timespec_valid_strict(const struct timespec *ts)
99 return true; 99 return true;
100} 100}
101 101
102static inline bool timeval_valid(const struct timeval *tv)
103{
104 /* Dates before 1970 are bogus */
105 if (tv->tv_sec < 0)
106 return false;
107
108 /* Can't have more microseconds then a second */
109 if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC)
110 return false;
111
112 return true;
113}
114
102extern struct timespec timespec_trunc(struct timespec t, unsigned gran); 115extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
103 116
104#define CURRENT_TIME (current_kernel_time()) 117#define CURRENT_TIME (current_kernel_time())