]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
posix-timers: Make forward callback return s64
authorThomas Gleixner <tglx@linutronix.de>
Tue, 26 Jun 2018 13:21:31 +0000 (15:21 +0200)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:50:54 +0000 (19:50 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836287
[ Upstream commit 6fec64e1c92d5c715c6d0f50786daa7708266bde ]

The posix timer ti_overrun handling is broken because the forwarding
functions can return a huge number of overruns which does not fit in an
int. As a consequence timer_getoverrun(2) and siginfo::si_overrun can turn
into random number generators.

As a first step to address that let the timer_forward() callbacks return
the full 64 bit value.

Cast it to (int) temporarily until k_itimer::ti_overrun is converted to
64bit and the conversion to user space visible values is sanitized.

Reported-by: Team OWL337 <icytxw@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Link: https://lkml.kernel.org/r/20180626132704.922098090@linutronix.de
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
kernel/time/alarmtimer.c
kernel/time/posix-timers.c
kernel/time/posix-timers.h

index 481bb6ca6ca040fcb20e9febf4176487c88f5cfe..fa5de5e8de61d88d266cd2651dedd2090ad89284 100644 (file)
@@ -581,11 +581,11 @@ static void alarm_timer_rearm(struct k_itimer *timr)
  * @timr:      Pointer to the posixtimer data struct
  * @now:       Current time to forward the timer against
  */
-static int alarm_timer_forward(struct k_itimer *timr, ktime_t now)
+static s64 alarm_timer_forward(struct k_itimer *timr, ktime_t now)
 {
        struct alarm *alarm = &timr->it.alarm.alarmtimer;
 
-       return (int) alarm_forward(alarm, timr->it_interval, now);
+       return alarm_forward(alarm, timr->it_interval, now);
 }
 
 /**
index 3192a986a483f86d187f3984311281e08f0aa266..0f0e2566ef89c52d93da864d1a961b0569f07350 100644 (file)
@@ -654,11 +654,11 @@ static ktime_t common_hrtimer_remaining(struct k_itimer *timr, ktime_t now)
        return __hrtimer_expires_remaining_adjusted(timer, now);
 }
 
-static int common_hrtimer_forward(struct k_itimer *timr, ktime_t now)
+static s64 common_hrtimer_forward(struct k_itimer *timr, ktime_t now)
 {
        struct hrtimer *timer = &timr->it.real.timer;
 
-       return (int)hrtimer_forward(timer, now, timr->it_interval);
+       return hrtimer_forward(timer, now, timr->it_interval);
 }
 
 /*
@@ -711,7 +711,7 @@ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
         * expiry time forward by intervals, so expiry is > now.
         */
        if (iv && (timr->it_requeue_pending & REQUEUE_PENDING || sig_none))
-               timr->it_overrun += kc->timer_forward(timr, now);
+               timr->it_overrun += (int)kc->timer_forward(timr, now);
 
        remaining = kc->timer_remaining(timr, now);
        /* Return 0 only, when the timer is expired and not pending */
index 151e28f5bf304ce134897038639c53998adae4d8..ddb21145211a0280f9b20667a33b9503ce62d776 100644 (file)
@@ -19,7 +19,7 @@ struct k_clock {
        void    (*timer_get)(struct k_itimer *timr,
                             struct itimerspec64 *cur_setting);
        void    (*timer_rearm)(struct k_itimer *timr);
-       int     (*timer_forward)(struct k_itimer *timr, ktime_t now);
+       s64     (*timer_forward)(struct k_itimer *timr, ktime_t now);
        ktime_t (*timer_remaining)(struct k_itimer *timr, ktime_t now);
        int     (*timer_try_to_cancel)(struct k_itimer *timr);
        void    (*timer_arm)(struct k_itimer *timr, ktime_t expires,