summaryrefslogtreecommitdiff
path: root/include/linux/time.h
diff options
context:
space:
mode:
authorSasha Levin <sasha.levin@oracle.com>2014-12-04 03:22:48 +0300
committerJohn Stultz <john.stultz@linaro.org>2015-01-07 20:49:14 +0300
commit6ada1fc0e1c4775de0e043e1bd3ae9d065491aa5 (patch)
treeb6a02726aa5f93ccb61e7161c7705590424f7830 /include/linux/time.h
parentb2776bf7149bddd1f4161f14f79520f17fc1d71d (diff)
downloadlinux-6ada1fc0e1c4775de0e043e1bd3ae9d065491aa5.tar.xz
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/linux/time.h')
-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)
return true;
}
+static inline bool timeval_valid(const struct timeval *tv)
+{
+ /* Dates before 1970 are bogus */
+ if (tv->tv_sec < 0)
+ return false;
+
+ /* Can't have more microseconds then a second */
+ if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC)
+ return false;
+
+ return true;
+}
+
extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
#define CURRENT_TIME (current_kernel_time())