android_kernel_motorola_sm6375/kernel/time
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Yu Liao 6288909493 timekeeping: Really make sure wall_to_monotonic isn't positive
commit 4e8c11b6b3f0b6a283e898344f154641eda94266 upstream.

Even after commit e1d7ba8735 ("time: Always make sure wall_to_monotonic
isn't positive") it is still possible to make wall_to_monotonic positive
by running the following code:

    int main(void)
    {
        struct timespec time;

        clock_gettime(CLOCK_MONOTONIC, &time);
        time.tv_nsec = 0;
        clock_settime(CLOCK_REALTIME, &time);
        return 0;
    }

The reason is that the second parameter of timespec64_compare(), ts_delta,
may be unnormalized because the delta is calculated with an open coded
substraction which causes the comparison of tv_sec to yield the wrong
result:

  wall_to_monotonic = { .tv_sec = -10, .tv_nsec =  900000000 }
  ts_delta 	    = { .tv_sec =  -9, .tv_nsec = -900000000 }

That makes timespec64_compare() claim that wall_to_monotonic < ts_delta,
but actually the result should be wall_to_monotonic > ts_delta.

After normalization, the result of timespec64_compare() is correct because
the tv_sec comparison is not longer misleading:

  wall_to_monotonic = { .tv_sec = -10, .tv_nsec =  900000000 }
  ts_delta 	    = { .tv_sec = -10, .tv_nsec =  100000000 }

Use timespec64_sub() to ensure that ts_delta is normalized, which fixes the
issue.

Fixes: e1d7ba8735 ("time: Always make sure wall_to_monotonic isn't positive")
Signed-off-by: Yu Liao <liaoyu15@huawei.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20211213135727.1656662-1-liaoyu15@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-12-22 09:29:39 +01:00
..
alarmtimer.c kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data() 2021-03-24 11:26:44 +01:00
clockevents.c
clocksource.c clocksource: Retry clock read if long delays detected 2021-07-14 16:53:18 +02:00
hrtimer.c hrtimer: Ensure timerfd notification for HIGHRES=n 2021-09-15 09:47:26 +02:00
itimer.c time: Prevent undefined behaviour in timespec64_to_ns() 2020-11-18 19:20:15 +01:00
jiffies.c
Kconfig
Makefile
ntp.c
ntp_internal.h
posix-clock.c
posix-cpu-timers.c Revert "posix-cpu-timers: Force next expiration recalc after itimer reset" 2021-09-16 12:56:13 +02:00
posix-stubs.c
posix-timers.c posix-timers: Preserve return value in clock_adjtime32() 2021-05-11 14:04:04 +02:00
posix-timers.h
sched_clock.c
test_udelay.c
tick-broadcast-hrtimer.c
tick-broadcast.c
tick-common.c tick/common: Touch watchdog in tick_unfreeze() on all CPUs 2020-11-18 19:20:26 +01:00
tick-internal.h hrtimer: Ensure timerfd notification for HIGHRES=n 2021-09-15 09:47:26 +02:00
tick-oneshot.c
tick-sched.c tick/sched: Remove bogus boot "safety" check 2021-01-06 14:48:40 +01:00
tick-sched.h
time.c
timeconst.bc
timeconv.c
timecounter.c
timekeeping.c timekeeping: Really make sure wall_to_monotonic isn't positive 2021-12-22 09:29:39 +01:00
timekeeping.h
timekeeping_debug.c
timekeeping_internal.h
timer.c timers: Move clearing of base::timer_running under base:: Lock 2021-08-12 13:21:03 +02:00
timer_list.c
vsyscall.c