LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "SZ Lin (林上智)" <sz.lin@moxa.com>
To: unlisted-recipients:; (no To-header on input)
Cc: "SZ Lin (林上智)" <sz.lin@moxa.com>,
	"Taiyi Wu" <taiyity.wu@moxa.com>,
	"Alessandro Zummo" <a.zummo@towertech.it>,
	"Alexandre Belloni" <alexandre.belloni@free-electrons.com>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RESEND PATCH] rtc: tps65910: add bounds checking
Date: Tue, 10 Apr 2018 15:24:17 +0800	[thread overview]
Message-ID: <20180410072417.7078-1-sz.lin@moxa.com> (raw)

Since tm->tm_year is the offset relative to 1900, it needs to check for
positive value to avoid overflow in YEARS_REG register.

The system will hang at the following stage on the next boot when overflow
has occurred.

[    2.221192] systemd[1]: Time has been changed

This patch fixes the above hanging issue by adding bounds checking.

Signed-off-by: Taiyi Wu <taiyity.wu@moxa.com>
Signed-off-by: SZ Lin (林上智) <sz.lin@moxa.com>
---
 drivers/rtc/rtc-tps65910.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
index d0244d7979fc..6be9f7bb0f1b 100644
--- a/drivers/rtc/rtc-tps65910.c
+++ b/drivers/rtc/rtc-tps65910.c
@@ -105,6 +105,12 @@ static int tps65910_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	struct tps65910 *tps = dev_get_drvdata(dev->parent);
 	int ret;
 
+	if ((tm->tm_year - 100) < 0) {
+		dev_err(dev, "the requested year %d is unsupported\n",
+			1900 + tm->tm_year);
+		return -EINVAL;
+	}
+
 	rtc_data[0] = bin2bcd(tm->tm_sec);
 	rtc_data[1] = bin2bcd(tm->tm_min);
 	rtc_data[2] = bin2bcd(tm->tm_hour);
-- 
2.17.0

             reply	other threads:[~2018-04-10  7:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-10  7:24 SZ Lin (林上智) [this message]
2018-04-10  7:56 ` [RESEND PATCH] rtc: tps65910: add bounds checking 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=20180410072417.7078-1-sz.lin@moxa.com \
    --to=sz.lin@moxa.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=taiyity.wu@moxa.com \
    /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).