gettimeofday.2, clock_getres.2: ERRORS: EINVAL can occur if new real time is less than monotonic clock

Attempts (settimeofday(), clcok_settime(CLOCK_REALTIME)) to set
the real time clock to a value less than the current value of the
CLOCK_MONOTONIC clock result in EINVAL.

In the kernel source file kernel/time/timekeeping.c::do_settimeofday64(),
there is this check:

        if (timespec64_compare(&tk->wall_to_monotonic, &ts_delta) > 0) {
                ret = -EINVAL;
                goto out;
        }

It appears that the check was added in Linux 4.3:

    commit e1d7ba8735551ed79c7a0463a042353574b96da3
    Author: Wang YanQing <udknight@gmail.com>
    Date:   Tue Jun 23 18:38:54 2015 +0800

        time: Always make sure wall_to_monotonic isn't positive

Reported-by: Jens Thoms Toerring <jt@toerring.de>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2018-05-13 16:21:03 +02:00
parent 018c296c7e
commit bccacb94dd
2 changed files with 22 additions and 0 deletions

View File

@ -212,6 +212,19 @@ is negative or
.I tp.tv_nsec
is outside the range [0..999,999,999].
.TP
.BR EINVAL " (since Linux 4.3)"
.\" commit e1d7ba8735551ed79c7a0463a042353574b96da3
A call to
.BR clock_settime ()
with a
.I clk_id
of
.B CLOCK_REALTIME
attempted to set the time to a value less than
the current value of the
.B CLOCK_MONOTONIC
clock.
.TP
.B EPERM
.BR clock_settime ()
does not have permission to set the clock indicated.

View File

@ -166,6 +166,15 @@ is negative or
.I tv.tv_usec
is outside the range [0..999,999].
.TP
.BR EINVAL " (since Linux 4.3)"
.\" commit e1d7ba8735551ed79c7a0463a042353574b96da3
.RB ( settimeofday ()):
An attempt was made to set the time to a value less than
the current value of the
.B CLOCK_MONOTONIC
clock (see
.BR clock_gettime (2)).
.TP
.B EPERM
The calling process has insufficient privilege to call
.BR settimeofday ();