All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Jinjie Ruan <ruanjinjie@huawei.com>,
	peter.maydell@linaro.org, mst@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2] hw/rtc/mc146818rtc: Fix get_guest_rtc_ns() overflow bug
Date: Mon, 11 May 2026 11:27:06 +0100	[thread overview]
Message-ID: <agGu-vg1lPvEjalp@redhat.com> (raw)
In-Reply-To: <92cecc93-1f68-44f2-8d0b-934e868d3e2c@redhat.com>

On Mon, May 11, 2026 at 09:06:54AM +0200, Paolo Bonzini wrote:
> On 1/14/26 02:32, Jinjie Ruan wrote:
> > In get_guest_rtc_ns(), "s->base_rtc" is uint64_t, which multiplied by
> > "NANOSECONDS_PER_SECOND" may overflow the uint64_t type, which will
> > cause the QEMU Linux Virtual Machine's RTC time to jump and in turn
> > triggers a kernel Soft Lockup and ultimately leads to a crash.
> > 
> > Fix it by avoiding adding s->base_rtc in get_guest_rtc_ns_offset(),
> > because get_guest_rtc_ns() is used either take the remainder of
> > NANOSECONDS_PER_SECOND or take the quotient of NANOSECONDS_PER_SECOND.
> > 
> > Fixes: 56038ef6234e ("RTC: Update the RTC clock only when reading it")
> > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> 
> Thanks, queued - I also renamed the function to
> get_rtc_ns_since_last_update().  It's not entirely accurate due the presence
> of the sub-second offset s->offset, but it's good enough.
> 
> I have also considered changing the function to return a struct timespec.  I
> didn't like it too much because struct timespec uses a time_t which is
> possibly 32-bit.  Now, QEMU is probably broken for Y2038 anyway, but having
> time_t dependencies in device emulation code is not great; at least mktimegm
> and gmtime_r could be rewritten easily.

For system mode at least, we can assume time_t will be 64-bit only
since we drop 32-bit host OS support.

For user mode, we can likewise assume 64-bit host OS, but still have
to deal with potential 32-bit time_t for the guest OS. One could
argue that in the user mode case though, the guest ABI is what is
broken for Y2038 - QEMU is just honouring the (broken) ABI that is
defined.

The tools could be impacted by 32-bit issues I guess, but we still
have 10+ years to kill off the 32-bit host OS build support for
tools

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



      parent reply	other threads:[~2026-05-11 10:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14  1:32 [PATCH v2] hw/rtc/mc146818rtc: Fix get_guest_rtc_ns() overflow bug Jinjie Ruan
2026-03-18  7:03 ` Jinjie Ruan
2026-04-22  3:07   ` Jinjie Ruan
2026-04-30 12:53     ` Peter Maydell
2026-05-11  3:10       ` Jinjie Ruan
2026-05-11  7:06 ` Paolo Bonzini
2026-05-11 10:22   ` Philippe Mathieu-Daudé
2026-05-11 10:27   ` Daniel P. Berrangé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=agGu-vg1lPvEjalp@redhat.com \
    --to=berrange@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ruanjinjie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.