* [PATCH v2] system/rtc: Fix a possible year-2038 integer overflow problem
@ 2026-05-18 16:34 Thomas Huth
2026-05-18 16:48 ` Daniel P. Berrangé
2026-05-18 16:57 ` Laurent Vivier
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Huth @ 2026-05-18 16:34 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-trivial, qemu-stable, Laurent Vivier,
Daniel P . Berrangé
From: Thomas Huth <thuth@redhat.com>
rtc_realtime_clock_offset is initialized with:
rtc_realtime_clock_offset = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
And QEMU_CLOCK_REALTIME might be based on gettimeofday() in certain
cases (see get_clock_realtime() in include/qemu/timer.h). So this
counter will exceed 32 bits in the year 2038, thus we should not
store this value in a normal integer variable. Change it to a time_t
to fix the problem.
And while we're at it, also adjust the nearby rtc_host_datetime_offset
variable to be on the safe side in the related code.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
v2: Use time_t instead of int64_t
system/rtc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/system/rtc.c b/system/rtc.c
index f13dd392a76..018609a4f9a 100644
--- a/system/rtc.c
+++ b/system/rtc.c
@@ -41,8 +41,8 @@ static enum {
RTC_BASE_DATETIME,
} rtc_base_type = RTC_BASE_UTC;
static time_t rtc_ref_start_datetime;
-static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */
-static int rtc_host_datetime_offset = -1; /* valid & used only with
+static time_t rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */
+static time_t rtc_host_datetime_offset = -1; /* valid & used only with
RTC_BASE_DATETIME */
QEMUClockType rtc_clock;
/***********************************************************/
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] system/rtc: Fix a possible year-2038 integer overflow problem
2026-05-18 16:34 [PATCH v2] system/rtc: Fix a possible year-2038 integer overflow problem Thomas Huth
@ 2026-05-18 16:48 ` Daniel P. Berrangé
2026-05-18 16:57 ` Laurent Vivier
1 sibling, 0 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2026-05-18 16:48 UTC (permalink / raw)
To: Thomas Huth; +Cc: qemu-devel, qemu-trivial, qemu-stable, Laurent Vivier
On Mon, May 18, 2026 at 06:34:08PM +0200, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
>
> rtc_realtime_clock_offset is initialized with:
>
> rtc_realtime_clock_offset = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
>
> And QEMU_CLOCK_REALTIME might be based on gettimeofday() in certain
> cases (see get_clock_realtime() in include/qemu/timer.h). So this
> counter will exceed 32 bits in the year 2038, thus we should not
> store this value in a normal integer variable. Change it to a time_t
> to fix the problem.
> And while we're at it, also adjust the nearby rtc_host_datetime_offset
> variable to be on the safe side in the related code.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> v2: Use time_t instead of int64_t
>
> system/rtc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
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 :|
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] system/rtc: Fix a possible year-2038 integer overflow problem
2026-05-18 16:34 [PATCH v2] system/rtc: Fix a possible year-2038 integer overflow problem Thomas Huth
2026-05-18 16:48 ` Daniel P. Berrangé
@ 2026-05-18 16:57 ` Laurent Vivier
1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2026-05-18 16:57 UTC (permalink / raw)
To: Thomas Huth, qemu-devel
Cc: qemu-trivial, qemu-stable, Daniel P . Berrangé
Le 18/05/2026 à 18:34, Thomas Huth a écrit :
> From: Thomas Huth <thuth@redhat.com>
>
> rtc_realtime_clock_offset is initialized with:
>
> rtc_realtime_clock_offset = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
>
> And QEMU_CLOCK_REALTIME might be based on gettimeofday() in certain
> cases (see get_clock_realtime() in include/qemu/timer.h). So this
> counter will exceed 32 bits in the year 2038, thus we should not
> store this value in a normal integer variable. Change it to a time_t
> to fix the problem.
> And while we're at it, also adjust the nearby rtc_host_datetime_offset
> variable to be on the safe side in the related code.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> v2: Use time_t instead of int64_t
>
> system/rtc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/system/rtc.c b/system/rtc.c
> index f13dd392a76..018609a4f9a 100644
> --- a/system/rtc.c
> +++ b/system/rtc.c
> @@ -41,8 +41,8 @@ static enum {
> RTC_BASE_DATETIME,
> } rtc_base_type = RTC_BASE_UTC;
> static time_t rtc_ref_start_datetime;
> -static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */
> -static int rtc_host_datetime_offset = -1; /* valid & used only with
> +static time_t rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */
> +static time_t rtc_host_datetime_offset = -1; /* valid & used only with
> RTC_BASE_DATETIME */
> QEMUClockType rtc_clock;
> /***********************************************************/
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-18 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 16:34 [PATCH v2] system/rtc: Fix a possible year-2038 integer overflow problem Thomas Huth
2026-05-18 16:48 ` Daniel P. Berrangé
2026-05-18 16:57 ` Laurent Vivier
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.