struct rtc_time follows the Linux convention: tm_year counts from 1900
and tm_mon is zero based. EFI_TIME on the other hand carries the full
year and a one based month.

efi_get_time_boottime() copied both fields over unchanged, so GetTime()
reported year 126 and month 6 for July 2026.

efi_set_time_boottime() has the mirrored problem. rtc_valid_tm() accepts
the result, since it only rejects tm_year below 70 and tm_mon of 12 or
more, so rtc_tm_to_time() goes on to compute
mktime(time->year + 1900, time->month + 1, ...) and the RTC is set
roughly 1900 years and one month ahead.

Convert in both directions.

Assisted-by: Codex:gpt-5.5
Fixes: 06947fd4664c ("efi: loader: add support for runtime services before 
ExitBootServices")
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 efi/loader/runtime.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/efi/loader/runtime.c b/efi/loader/runtime.c
index f0fbd263fe55..024d402b3915 100644
--- a/efi/loader/runtime.c
+++ b/efi/loader/runtime.c
@@ -173,8 +173,8 @@ static efi_status_t EFIAPI efi_get_time_boottime(
        }
 
        memset(time, 0, sizeof(*time));
-       time->year = tm.tm_year;
-       time->month = tm.tm_mon;
+       time->year = tm.tm_year + 1900;
+       time->month = tm.tm_mon + 1;
        time->day = tm.tm_mday;
        time->hour = tm.tm_hour;
        time->minute = tm.tm_min;
@@ -257,8 +257,8 @@ static efi_status_t EFIAPI efi_set_time_boottime(struct 
efi_time *time)
        }
 
        memset(&tm, 0, sizeof(tm));
-       tm.tm_year = time->year;
-       tm.tm_mon = time->month;
+       tm.tm_year = time->year - 1900;
+       tm.tm_mon = time->month - 1;
        tm.tm_mday = time->day;
        tm.tm_hour = time->hour;
        tm.tm_min = time->minute;
-- 
2.47.3


Reply via email to