|
|
f892dd8 |
commit 5361ad3910c257bc327567be76fde532ed238e42
|
|
|
f892dd8 |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
f892dd8 |
Date: Fri Apr 19 14:38:17 2024 +0200
|
|
|
f892dd8 |
|
|
|
f892dd8 |
login: Use unsigned 32-bit types for seconds-since-epoch
|
|
|
f892dd8 |
|
|
|
f892dd8 |
These fields store timestamps when the system was running. No Linux
|
|
|
f892dd8 |
systems existed before 1970, so these values are unused. Switching
|
|
|
f892dd8 |
to unsigned types allows continued use of the existing struct layouts
|
|
|
f892dd8 |
beyond the year 2038.
|
|
|
f892dd8 |
|
|
|
f892dd8 |
The intent is to give distributions more time to switch to improved
|
|
|
f892dd8 |
interfaces that also avoid locking/data corruption issues.
|
|
|
f892dd8 |
|
|
|
f892dd8 |
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
f892dd8 |
|
|
|
f892dd8 |
diff --git a/bits/utmp.h b/bits/utmp.h
|
|
|
f892dd8 |
index f2d1c13d8cd205b2..27cb536800c46d67 100644
|
|
|
f892dd8 |
--- a/bits/utmp.h
|
|
|
f892dd8 |
+++ b/bits/utmp.h
|
|
|
f892dd8 |
@@ -36,7 +36,7 @@
|
|
|
f892dd8 |
struct lastlog
|
|
|
f892dd8 |
{
|
|
|
f892dd8 |
#if __WORDSIZE_TIME64_COMPAT32
|
|
|
f892dd8 |
- int32_t ll_time;
|
|
|
f892dd8 |
+ __uint32_t ll_time;
|
|
|
f892dd8 |
#else
|
|
|
f892dd8 |
__time_t ll_time;
|
|
|
f892dd8 |
#endif
|
|
|
f892dd8 |
@@ -76,7 +76,7 @@ struct utmp
|
|
|
f892dd8 |
int32_t ut_session; /* Session ID, used for windowing. */
|
|
|
f892dd8 |
struct
|
|
|
f892dd8 |
{
|
|
|
f892dd8 |
- int32_t tv_sec; /* Seconds. */
|
|
|
f892dd8 |
+ __uint32_t tv_sec; /* Seconds. */
|
|
|
f892dd8 |
int32_t tv_usec; /* Microseconds. */
|
|
|
f892dd8 |
} ut_tv; /* Time entry was made. */
|
|
|
f892dd8 |
#else
|
|
|
f892dd8 |
diff --git a/login/Makefile b/login/Makefile
|
|
|
f892dd8 |
index f91190e3dcd1e6c6..84563230ef665f9c 100644
|
|
|
f892dd8 |
--- a/login/Makefile
|
|
|
f892dd8 |
+++ b/login/Makefile
|
|
|
f892dd8 |
@@ -44,9 +44,11 @@ subdir-dirs = programs
|
|
|
f892dd8 |
vpath %.c programs
|
|
|
f892dd8 |
|
|
|
f892dd8 |
tests := tst-utmp tst-utmpx tst-grantpt tst-ptsname tst-getlogin tst-updwtmpx \
|
|
|
f892dd8 |
- tst-pututxline-lockfail tst-pututxline-cache tst-utmp-size tst-utmp-size-64
|
|
|
f892dd8 |
+ tst-pututxline-lockfail tst-pututxline-cache tst-utmp-size tst-utmp-size-64 \
|
|
|
f892dd8 |
+ tst-utmp-unsigned tst-utmp-unsigned-64
|
|
|
f892dd8 |
|
|
|
f892dd8 |
CFLAGS-tst-utmp-size-64.c += -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
|
|
|
f892dd8 |
+CFLAGS-tst-utmp-unsigned-64.c += -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
|
|
|
f892dd8 |
|
|
|
f892dd8 |
# Empty compatibility library for old binaries.
|
|
|
f892dd8 |
extra-libs := libutil
|
|
|
f892dd8 |
diff --git a/login/tst-utmp-unsigned-64.c b/login/tst-utmp-unsigned-64.c
|
|
|
f892dd8 |
new file mode 100644
|
|
|
f892dd8 |
index 0000000000000000..940e7654f8dc5fd6
|
|
|
f892dd8 |
--- /dev/null
|
|
|
f892dd8 |
+++ b/login/tst-utmp-unsigned-64.c
|
|
|
f892dd8 |
@@ -0,0 +1 @@
|
|
|
f892dd8 |
+#include "tst-utmp-unsigned.c"
|
|
|
f892dd8 |
diff --git a/login/tst-utmp-unsigned.c b/login/tst-utmp-unsigned.c
|
|
|
f892dd8 |
new file mode 100644
|
|
|
f892dd8 |
index 0000000000000000..27ad03a7d608e83d
|
|
|
f892dd8 |
--- /dev/null
|
|
|
f892dd8 |
+++ b/login/tst-utmp-unsigned.c
|
|
|
f892dd8 |
@@ -0,0 +1,40 @@
|
|
|
f892dd8 |
+/* Check that struct utmp, struct utmpx, struct lastlog use unsigned epoch.
|
|
|
f892dd8 |
+ Copyright (C) 2024 Free Software Foundation, Inc.
|
|
|
f892dd8 |
+ This file is part of the GNU C Library.
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
f892dd8 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
f892dd8 |
+ License as published by the Free Software Foundation; either
|
|
|
f892dd8 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
f892dd8 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
f892dd8 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
f892dd8 |
+ Lesser General Public License for more details.
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
f892dd8 |
+ License along with the GNU C Library; if not, see
|
|
|
f892dd8 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+#include <utmp.h>
|
|
|
f892dd8 |
+#include <utmpx.h>
|
|
|
f892dd8 |
+#include <utmp-size.h>
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+/* Undefined. Used to check that the conditions below are optimized away. */
|
|
|
f892dd8 |
+void link_failure_utmp (void);
|
|
|
f892dd8 |
+void link_failure_utmpx (void);
|
|
|
f892dd8 |
+void link_failure_lastlog (void);
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+static int
|
|
|
f892dd8 |
+do_test (void)
|
|
|
f892dd8 |
+{
|
|
|
f892dd8 |
+ if ((struct utmp) { .ut_tv = { 0x80000000U, }, }.ut_tv.tv_sec <= 0)
|
|
|
f892dd8 |
+ link_failure_utmp ();
|
|
|
f892dd8 |
+ if ((struct utmpx) { .ut_tv = { 0x80000000U, }, }.ut_tv.tv_sec <= 0)
|
|
|
f892dd8 |
+ link_failure_utmpx ();
|
|
|
f892dd8 |
+ if ((struct lastlog) { .ll_time = 0x80000000U, }.ll_time <= 0)
|
|
|
f892dd8 |
+ link_failure_lastlog ();
|
|
|
f892dd8 |
+ return 0;
|
|
|
f892dd8 |
+}
|
|
|
f892dd8 |
+
|
|
|
f892dd8 |
+#include <support/test-driver.c>
|
|
|
f892dd8 |
diff --git a/sysdeps/gnu/bits/utmpx.h b/sysdeps/gnu/bits/utmpx.h
|
|
|
f892dd8 |
index 34b4afbc6ac25968..ed0df9bd8141d4e6 100644
|
|
|
f892dd8 |
--- a/sysdeps/gnu/bits/utmpx.h
|
|
|
f892dd8 |
+++ b/sysdeps/gnu/bits/utmpx.h
|
|
|
f892dd8 |
@@ -74,7 +74,7 @@ struct utmpx
|
|
|
f892dd8 |
__int32_t ut_session; /* Session ID, used for windowing. */
|
|
|
f892dd8 |
struct
|
|
|
f892dd8 |
{
|
|
|
f892dd8 |
- __int32_t tv_sec; /* Seconds. */
|
|
|
f892dd8 |
+ __uint32_t tv_sec; /* Seconds. */
|
|
|
f892dd8 |
__int32_t tv_usec; /* Microseconds. */
|
|
|
f892dd8 |
} ut_tv; /* Time entry was made. */
|
|
|
f892dd8 |
#else
|