lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1a1c32fe-d124-0e47-c9e4-695be7ea7567@redhat.com>
Date:   Thu, 4 Jun 2020 22:14:11 +0200
From:   Paolo Bonzini <pbonzini@...hat.com>
To:     Miklos Szeredi <miklos@...redi.hu>,
        Thomas Gleixner <tglx@...utronix.de>
Cc:     kvm@...r.kernel.org, Vincenzo Frascino <vincenzo.frascino@....com>,
        Juergen Gross <jgross@...e.com>, linux-kernel@...r.kernel.org
Subject: Re: system time goes weird in kvm guest after host suspend/resume

On 04/06/20 21:28, Miklos Szeredi wrote:
> time(2) returns good time, while clock_gettime(2) returns bad time.
> Here's an example:
> 
> time=1591298725 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
> time=1591298726 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
> time=1591298727 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
> time=1591298728 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
> time=1591298729 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
> 
> As you can see, only time(2) is updated, the others remain the same.
> date(1) uses clock_gettime(CLOCK_REALTIME) so that shows the bad date.
> 
> When the correct time reaches the value returned by CLOCK_REALTIME,
> the value jumps exactly 2199 seconds.

clockid_to_kclock(CLOCK_REALTIME) is &clock_realtime, so clock_gettime
calls ktime_get_real_ts64, which is:


        do {
                seq = read_seqcount_begin(&tk_core.seq);

                ts->tv_sec = tk->xtime_sec;
                nsecs = timekeeping_get_ns(&tk->tkr_mono);

        } while (read_seqcount_retry(&tk_core.seq, seq));

        ts->tv_nsec = 0;
        timespec64_add_ns(ts, nsecs);

time(2) instead should actually be gettimeofday(2), which just returns
tk->xtime_sec.  So the problem is the nanosecond part which is off by
2199*10^9 nanoseconds, and that is suspiciously close to 2^31...

Paolo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ