aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/hrtimer.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2008-02-13 03:20:43 -0500
committerThomas Gleixner <tglx@linutronix.de>2008-02-14 16:08:30 -0500
commit5a7780e725d1bb4c3094fcc12f1c5c5faea1e988 (patch)
tree50fc5cde427f3854d0b84ba1037fef3fb4693e11 /kernel/hrtimer.c
parente760e716d47b48caf98da348368fd41b4a9b9e7e (diff)
hrtimer: check relative timeouts for overflow
Various user space callers ask for relative timeouts. While we fixed that overflow issue in hrtimer_start(), the sites which convert relative user space values to absolute timeouts themself were uncovered. Instead of putting overflow checks into each place add a function which does the sanity checking and convert all affected callers to use it. Thanks to Frans Pop, who reported the problem and tested the fixes. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Ingo Molnar <mingo@elte.hu> Tested-by: Frans Pop <elendil@planet.nl>
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r--kernel/hrtimer.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 3f4a57c7895d..c2893af9479e 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -326,6 +326,23 @@ u64 ktime_divns(const ktime_t kt, s64 div)
326#endif /* BITS_PER_LONG >= 64 */ 326#endif /* BITS_PER_LONG >= 64 */
327 327
328/* 328/*
329 * Add two ktime values and do a safety check for overflow:
330 */
331ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs)
332{
333 ktime_t res = ktime_add(lhs, rhs);
334
335 /*
336 * We use KTIME_SEC_MAX here, the maximum timeout which we can
337 * return to user space in a timespec:
338 */
339 if (res.tv64 < 0 || res.tv64 < lhs.tv64 || res.tv64 < rhs.tv64)
340 res = ktime_set(KTIME_SEC_MAX, 0);
341
342 return res;
343}
344
345/*
329 * Check, whether the timer is on the callback pending list 346 * Check, whether the timer is on the callback pending list
330 */ 347 */
331static inline int hrtimer_cb_pending(const struct hrtimer *timer) 348static inline int hrtimer_cb_pending(const struct hrtimer *timer)
@@ -682,13 +699,7 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
682 */ 699 */
683 orun++; 700 orun++;
684 } 701 }
685 timer->expires = ktime_add(timer->expires, interval); 702 timer->expires = ktime_add_safe(timer->expires, interval);
686 /*
687 * Make sure, that the result did not wrap with a very large
688 * interval.
689 */
690 if (timer->expires.tv64 < 0)
691 timer->expires = ktime_set(KTIME_SEC_MAX, 0);
692 703
693 return orun; 704 return orun;
694} 705}
@@ -839,7 +850,7 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
839 new_base = switch_hrtimer_base(timer, base); 850 new_base = switch_hrtimer_base(timer, base);
840 851
841 if (mode == HRTIMER_MODE_REL) { 852 if (mode == HRTIMER_MODE_REL) {
842 tim = ktime_add(tim, new_base->get_time()); 853 tim = ktime_add_safe(tim, new_base->get_time());
843 /* 854 /*
844 * CONFIG_TIME_LOW_RES is a temporary way for architectures 855 * CONFIG_TIME_LOW_RES is a temporary way for architectures
845 * to signal that they simply return xtime in 856 * to signal that they simply return xtime in
@@ -848,16 +859,8 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
848 * timeouts. This will go away with the GTOD framework. 859 * timeouts. This will go away with the GTOD framework.
849 */ 860 */
850#ifdef CONFIG_TIME_LOW_RES 861#ifdef CONFIG_TIME_LOW_RES
851 tim = ktime_add(tim, base->resolution); 862 tim = ktime_add_safe(tim, base->resolution);
852#endif 863#endif
853 /*
854 * Careful here: User space might have asked for a
855 * very long sleep, so the add above might result in a
856 * negative number, which enqueues the timer in front
857 * of the queue.
858 */
859 if (tim.tv64 < 0)
860 tim.tv64 = KTIME_MAX;
861 } 864 }
862 timer->expires = tim; 865 timer->expires = tim;
863 866