From patchwork Sat Feb 20 19:10:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 585661 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lf0-x240.google.com (mail-lf0-x240.google.com [IPv6:2a00:1450:4010:c07::240]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A149714032A for ; Sun, 21 Feb 2016 06:12:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=AEElTn+x; dkim-atps=neutral Received: by mail-lf0-x240.google.com with SMTP id e36sf22445016lfi.0 for ; Sat, 20 Feb 2016 11:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:x-original-sender :x-original-authentication-results:reply-to:content-type:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:sender:list-subscribe:list-unsubscribe; bh=ANs1KhjtOjprIOu9mN010+0LVXwBM/wxQv6678icvlA=; b=AEElTn+x4jfmk+4jiMUxWht9DwtnHa6hwVwftfeiSh6YsZmNRqxhtdVmrp6v4s3dds 1ncV/ZAVeTmtuhUVJPF7lQ3CBd+UZaPgeklVJNUctckh/WFp2TPrXpVMZr4okfDZz62A 7B9voU5bey14SA1OET/NteEFX+soYXJ1SxVtg8kSmOlslBUKon3gIJjL7A9MwjDypmk7 /0jZCj7cAJKiJtmf6k0vVekKQo2fD8PYIxgB+kKtrUvZsDTDAahgfEJq/+/jcyEswH51 0exEAqPFZgGRLrh4LB1bs5eh3eGa/2B/5TFSv/mFKpJJedBDGM5ziMM2Wgz0MoDqiakF cvpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:reply-to :content-type:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe; bh=ANs1KhjtOjprIOu9mN010+0LVXwBM/wxQv6678icvlA=; b=L/ISw45hXM56Y5jy1qPnmDKC44OW0QNSXEKyiBdpYhyx7OoqCbaMwGTXZ2I/PM7G/n w3Zy6yV91HF3vb0q55CUOHBK7Na7o4Ucqlirs7JeoV0O+s1pTSkHPJLJy8AbH8apCNUf l6hji8Kkfsis4XOE2nazcnjLuJucPpDvTkJWs5fKs7rEAp3QP9i0cnG0rz8lAhNNRQYM 3x6yG76yFVewa1G4zDG7vJkYHyyJDTxIHHLHV8QKBnM+cymHTuaLRG/GTIePQRKd0V/d RcCTws4iFDieiaxbNV0ty7KJ906OnrX0EjNWkgDb57JWsOL8EjgBTpvBL3XO7U/PHNp8 Yq4Q== X-Gm-Message-State: AG10YOQ4Pv8/RJl89FeeHD0qouEOYBQMNZNsjMYsWljOr1nBlR0NA5CC4Lipgtbh8NV4Tg== X-Received: by 10.28.223.198 with SMTP id w189mr20733wmg.18.1455995570726; Sat, 20 Feb 2016 11:12:50 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.28.145.2 with SMTP id t2ls147428wmd.2.gmail; Sat, 20 Feb 2016 11:12:50 -0800 (PST) X-Received: by 10.194.85.169 with SMTP id i9mr2555327wjz.4.1455995570352; Sat, 20 Feb 2016 11:12:50 -0800 (PST) Received: from mail.free-electrons.com (down.free-electrons.com. [37.187.137.238]) by gmr-mx.google.com with ESMTP id c143si679674wmd.1.2016.02.20.11.12.50 for ; Sat, 20 Feb 2016 11:12:50 -0800 (PST) Received-SPF: pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) client-ip=37.187.137.238; Received: by mail.free-electrons.com (Postfix, from userid 110) id C8CD117C0; Sat, 20 Feb 2016 20:12:49 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id A2ADF1793; Sat, 20 Feb 2016 20:12:49 +0100 (CET) From: Alexandre Belloni To: rtc-linux@googlegroups.com Cc: Alessandro Zummo , Arnd Bergmann , Willy Tarreau , linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [rtc-linux] [PATCH] rtc: Add an option to invalidate dates in 2038 Date: Sat, 20 Feb 2016 20:10:44 +0100 Message-Id: <1455995444-14146-1-git-send-email-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.7.0 X-Original-Sender: alexandre.belloni@free-electrons.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) smtp.mailfrom=alexandre.belloni@free-electrons.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , 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 --- 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);