Received: by 10.223.148.5 with SMTP id 5csp5946986wrq; Wed, 17 Jan 2018 07:34:43 -0800 (PST) X-Google-Smtp-Source: ACJfBosk5jmmd7hu6g69q92nBgP/ziJo3UyaVUtz9Xx0BUGrQNpm235nj477xYGGLZRBkajvwiO1 X-Received: by 10.101.89.75 with SMTP id g11mr18458435pgu.28.1516203283594; Wed, 17 Jan 2018 07:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516203283; cv=none; d=google.com; s=arc-20160816; b=NtK8YHjgk7AZ7JDp4eJ9G8JrwVDgSJCyDdmgb5tY7+/GRY37c+pKxl8U5bmKmya6kN qL45cckSk6kSu26mLRTMYBtIQ+FRL/D8vUosVoX2HnTUFK/UH/773zGy9kS5ZE8HR7n0 EExJ11hxn86BUMPEmAEGRWqPpZ5/vJPcnn5NtUFzm12nzpfdpGibf4CqBxSDShfmezdc Cm9MSez4dzV6/HEesiRKyxVkXIUccDGqWKMrgJwFGtrshh1DPSNhSKRV28qbTfcS3PAw LVaBhJEbKS8GM733hBIFTd5G8TlV5UMYkSzY7/ySa/ahxa+sgsZLRG7+9bjIWmWTVXj9 NHRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:arc-authentication-results; bh=/Tpua4K2KIuIeAh1A9cAu3aeGjfFwfmoE3wyhUiyjIw=; b=uHmrV0aPE3+Nl+qUxT+8ktZH0Tvmvx+myImc5IebmQLVrKg/BmAg8oEfF32FgnpQ+5 yvyvOLK4X1XQq+DCOdHPAM2vOQ8sHGp6g1OsBlSp7VnCBUK/9g+NXeulnI4Emae1lS3T p9C/M+4TVGXZzK+tWb7Sxc0KYGD2zCL/Dyy0CqwVIQvAKumfpHJLrTQQQOMDLMdAbCTe CPSi4M3unZZ06jsqfoxbTePKFN2R2gPVGObTPw6zTmyc+79DDdTeUv7LeXg9CzfMaViy cftVuIR9f8r/KMlIxvwBL4p5SMePQf4Z/2xR/xfkBINJklNXppR3sO+LhGgYjrag4VcB JkJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si999701plg.575.2018.01.17.07.34.29; Wed, 17 Jan 2018 07:34:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754034AbeAQPce (ORCPT + 99 others); Wed, 17 Jan 2018 10:32:34 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40407 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753376AbeAQPcc (ORCPT ); Wed, 17 Jan 2018 10:32:32 -0500 Received: by mail-pf0-f194.google.com with SMTP id i66so11727334pfd.7; Wed, 17 Jan 2018 07:32:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Tpua4K2KIuIeAh1A9cAu3aeGjfFwfmoE3wyhUiyjIw=; b=CG3aQJjizidSy1esC4pLac5yjfU0vEim09Dqt+2mc+AcAn5yadZ/QWFB2AXJvSTClP 72R+cngWC3qd7Ijg8nzgxraFESinbpM5iR6sWcwj7MzPo0sndKr6LTlaqSnbVWRKsxcD AeSbOT8v3DsubNWe/4eO+Ym/m5XlPYpvfFDhQTYjNDZkOoJNI7w+jGYuLGjJNZ6zRhNS 2GGZf+KJEBYE3gXVyJxcol4f8xs5IpNiC0MZ9ZITOi0v3y5URm/zGyvkhfsY3x0oK5mj jNeKdRkSx5TmpQaL0EgY908NmfdNdZVdYGt88VzHoyQBnrAzIxLs0Kg5OAaKAxdNCzI1 +FlQ== X-Gm-Message-State: AKwxytfeXTNxVzWocHQKOX+kjVqPsNsDSHlEjKsh55cAHwiMWcdTIhvg WTMn9D/8uq/J/ZrYmQpHlHo= X-Received: by 10.98.72.19 with SMTP id v19mr14545383pfa.107.1516203151786; Wed, 17 Jan 2018 07:32:31 -0800 (PST) Received: from szlin-TW ([122.146.92.136]) by smtp.gmail.com with ESMTPSA id u195sm8256964pgb.64.2018.01.17.07.32.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Jan 2018 07:32:30 -0800 (PST) Received: from root by szlin-TW with local (Exim 4.90) (envelope-from ) id 1ebphU-0004cy-N7; Wed, 17 Jan 2018 23:32:28 +0800 From: =?UTF-8?q?SZ=20Lin=20=28=E6=9E=97=E4=B8=8A=E6=99=BA=29?= Cc: =?UTF-8?q?SZ=20Lin=20=28=E6=9E=97=E4=B8=8A=E6=99=BA=29?= , Taiyi Wu , Alessandro Zummo , Alexandre Belloni , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rtc: tps65910: add bounds checking Date: Wed, 17 Jan 2018 23:30:47 +0800 Message-Id: <20180117153048.17727-1-sz.lin@moxa.com> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: SZ Lin (林上智) --- 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.15.1