linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: rtc-linux@googlegroups.com
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Arnd Bergmann <arnd@arndb.de>, Willy Tarreau <w@1wt.eu>,
	linux-kernel@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>
Subject: [PATCH] rtc: Add an option to invalidate dates in 2038
Date: Sat, 20 Feb 2016 20:10:44 +0100	[thread overview]
Message-ID: <1455995444-14146-1-git-send-email-alexandre.belloni@free-electrons.com> (raw)

hctosys is setting the system time from the kernel. This means that 32bit
system can get their time set to a date after the 31bit time_t overflow.

This is currently an issue as userspace is not yet ready to handle those
dates and may break. For example systemd's usage of timerfd shows that the
timerfd will always fire immediately because it can't be set at a date
after the current date.

The new RTC_INVALID_2038 option will make sure that date after 03:09:07 on
Jan 19 2038 are invalid. This is 5 minutes before the 31bit overflow. This
leaves enough time for userspace to react and is short enough to make the
issue visible.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/rtc/Kconfig   | 10 ++++++++++
 drivers/rtc/rtc-lib.c |  5 ++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 376322f71fd5..fc087855e6a9 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -73,6 +73,16 @@ config RTC_DEBUG
 	  Say yes here to enable debugging support in the RTC framework
 	  and individual RTC drivers.
 
+config RTC_INVALID_2038
+	bool "Invalidate dates after 2038"
+	depends on !64BIT
+	default y
+	help
+	  Saying yes here will make any date after 03:09:07 on Jan 19 2038
+	  invalid (this is 5 minutes before the 31 bits overflow of a time_t).
+	  This is useful if your userspace is not yet ready to handle 64 bits
+	  times.
+
 comment "RTC interfaces"
 
 config RTC_INTF_SYSFS
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index e6bfb9c42a10..1ba148256afc 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -107,7 +107,10 @@ int rtc_valid_tm(struct rtc_time *tm)
 		|| ((unsigned)tm->tm_min) >= 60
 		|| ((unsigned)tm->tm_sec) >= 60)
 		return -EINVAL;
-
+#ifdef CONFIG_RTC_INVALID_2038
+	if (rtc_tm_to_time64(tm) > 0x7FFFFED4) /* 5 minutes before overflow */
+		return -EINVAL;
+#endif
 	return 0;
 }
 EXPORT_SYMBOL(rtc_valid_tm);
-- 
2.7.0

             reply	other threads:[~2016-02-20 19:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-20 19:10 Alexandre Belloni [this message]
2016-02-20 19:43 ` [PATCH] rtc: Add an option to invalidate dates in 2038 One Thousand Gnomes
2016-02-20 20:47   ` Alexandre Belloni
2016-02-20 22:16     ` Arnd Bergmann
2016-02-20 23:17       ` Alexandre Belloni
2016-02-20 23:42         ` Alexandre Belloni
2016-02-21 12:40         ` One Thousand Gnomes
2016-02-22 13:00           ` Alexandre Belloni
2016-02-22 13:43             ` One Thousand Gnomes
2016-02-22 15:44               ` Arnd Bergmann
2016-02-22 15:56                 ` Alexandre Belloni
2016-02-22 16:18                   ` Arnd Bergmann
2016-02-22 16:40                     ` Alexandre Belloni
2016-02-22 16:41                     ` Austin S. Hemmelgarn
2016-02-22 16:58                       ` Alexandre Belloni

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=1455995444-14146-1-git-send-email-alexandre.belloni@free-electrons.com \
    --to=alexandre.belloni@free-electrons.com \
    --cc=a.zummo@towertech.it \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rtc-linux@googlegroups.com \
    --cc=w@1wt.eu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).