Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754923AbbLDEBg (ORCPT ); Thu, 3 Dec 2015 23:01:36 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:29575 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754821AbbLDEBf (ORCPT ); Thu, 3 Dec 2015 23:01:35 -0500 From: Sasha Levin To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Sasha Levin Subject: [PATCH v2] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Date: Thu, 3 Dec 2015 23:01:14 -0500 Message-Id: <1449201674-24344-1-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 2.5.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1204 Lines: 37 At some point after humans go extinct and robots cotrol the world, dividing he time64_t by 86400 to extract the days will overflow a 32bit integer, leading to incorrect conversion into rtc_time in rtc_time64_to_tm(). Signed-off-by: Sasha Levin --- drivers/rtc/rtc-lib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index e6bfb9c..cafae93 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -53,12 +53,11 @@ EXPORT_SYMBOL(rtc_year_days); void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) { unsigned int month, year; - unsigned long secs; - int days; + int secs; + time64_t days; /* time must be positive */ - days = div_s64(time, 86400); - secs = time - (unsigned int) days * 86400; + days = div_s64_rem(time, 86400, &secs); /* day of the week, 1970-01-01 was a Thursday */ tm->tm_wday = (days + 4) % 7; -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/