public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
@ 2015-12-04  0:12 Sasha Levin
  2015-12-04  0:21 ` kbuild test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sasha Levin @ 2015-12-04  0:12 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: rtc-linux, linux-kernel, Sasha Levin

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 <sasha.levin@oracle.com>
---
 drivers/rtc/rtc-lib.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index e6bfb9c..459cd4d 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -54,11 +54,11 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
 {
 	unsigned int month, year;
 	unsigned long secs;
-	int days;
+	time64_t days;
 
 	/* time must be positive */
 	days = div_s64(time, 86400);
-	secs = time - (unsigned int) days * 86400;
+	secs = time - days * 86400;
 
 	/* day of the week, 1970-01-01 was a Thursday */
 	tm->tm_wday = (days + 4) % 7;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
  2015-12-04  0:12 [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Sasha Levin
@ 2015-12-04  0:21 ` kbuild test robot
  2015-12-04  1:39 ` kbuild test robot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2015-12-04  0:21 UTC (permalink / raw)
  To: Sasha Levin
  Cc: kbuild-all, a.zummo, alexandre.belloni, rtc-linux, linux-kernel,
	Sasha Levin

[-- Attachment #1: Type: text/plain, Size: 986 bytes --]

[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
Hi Sasha,

[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on v4.4-rc3 next-20151202]

url:    https://github.com/0day-ci/linux/commits/Sasha-Levin/rtc-fix-overflow-and-incorrect-calculation-in-rtc_time64_to_tm/20151204-081508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: i386-tinyconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/built-in.o: In function `rtc_time64_to_tm':
>> (.text+0x6795): undefined reference to `__moddi3'
   drivers/built-in.o: In function `rtc_time64_to_tm':
>> (.text+0x67aa): undefined reference to `__divdi3'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 6098 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
  2015-12-04  0:12 [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Sasha Levin
  2015-12-04  0:21 ` kbuild test robot
@ 2015-12-04  1:39 ` kbuild test robot
  2015-12-04  1:41 ` kbuild test robot
  2015-12-04  1:55 ` Alexandre Belloni
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2015-12-04  1:39 UTC (permalink / raw)
  To: Sasha Levin
  Cc: kbuild-all, a.zummo, alexandre.belloni, rtc-linux, linux-kernel,
	Sasha Levin

[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]

[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
Hi Sasha,

[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on v4.4-rc3 next-20151202]

url:    https://github.com/0day-ci/linux/commits/Sasha-Levin/rtc-fix-overflow-and-incorrect-calculation-in-rtc_time64_to_tm/20151204-081508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: avr32-mimc200_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=avr32 

All errors (new ones prefixed by >>):

   crypto/built-in.o: warning: input is not relaxable
   virt/built-in.o: warning: input is not relaxable
   drivers/built-in.o: In function `phy_device_create':
>> (.text+0x3c70c): undefined reference to `__avr32_smod64'
   drivers/built-in.o: In function `phy_device_create':
   (.text+0x3c710): undefined reference to `__avr32_sdiv64'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 11309 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
  2015-12-04  0:12 [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Sasha Levin
  2015-12-04  0:21 ` kbuild test robot
  2015-12-04  1:39 ` kbuild test robot
@ 2015-12-04  1:41 ` kbuild test robot
  2015-12-04  1:55 ` Alexandre Belloni
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2015-12-04  1:41 UTC (permalink / raw)
  To: Sasha Levin
  Cc: kbuild-all, a.zummo, alexandre.belloni, rtc-linux, linux-kernel,
	Sasha Levin

[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]

[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
Hi Sasha,

[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on v4.4-rc3 next-20151202]

url:    https://github.com/0day-ci/linux/commits/Sasha-Levin/rtc-fix-overflow-and-incorrect-calculation-in-rtc_time64_to_tm/20151204-081508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
config: arm-prima2_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   drivers/built-in.o: In function `rtc_time64_to_tm':
>> drivers/rtc/rtc-lib.c:64: undefined reference to `__aeabi_ldivmod'
   drivers/rtc/rtc-lib.c:66: undefined reference to `__aeabi_ldivmod'

vim +64 drivers/rtc/rtc-lib.c

c58411e9 Alessandro Zummo 2006-03-27  58  
c2c11ae4 pang.xunlei      2014-11-18  59  	/* time must be positive */
c2c11ae4 pang.xunlei      2014-11-18  60  	days = div_s64(time, 86400);
ee9fd0e8 Sasha Levin      2015-12-03  61  	secs = time - days * 86400;
c58411e9 Alessandro Zummo 2006-03-27  62  
c58411e9 Alessandro Zummo 2006-03-27  63  	/* day of the week, 1970-01-01 was a Thursday */
c58411e9 Alessandro Zummo 2006-03-27 @64  	tm->tm_wday = (days + 4) % 7;
c58411e9 Alessandro Zummo 2006-03-27  65  
c58411e9 Alessandro Zummo 2006-03-27  66  	year = 1970 + days / 365;
c58411e9 Alessandro Zummo 2006-03-27  67  	days -= (year - 1970) * 365

:::::: The code at line 64 was first introduced by commit
:::::: c58411e95d7f5062dedd1a3064af4d359da1e633 [PATCH] RTC Subsystem: library functions

:::::: TO: Alessandro Zummo <a.zummo@towertech.it>
:::::: CC: Linus Torvalds <torvalds@g5.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 12388 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
  2015-12-04  0:12 [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Sasha Levin
                   ` (2 preceding siblings ...)
  2015-12-04  1:41 ` kbuild test robot
@ 2015-12-04  1:55 ` Alexandre Belloni
  2015-12-04  2:06   ` Sasha Levin
  3 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2015-12-04  1:55 UTC (permalink / raw)
  To: Sasha Levin; +Cc: a.zummo, rtc-linux, linux-kernel

On 03/12/2015 at 19:12:24 -0500, Sasha Levin wrote :
> 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().
> 

And at that time, the robots won't care about 32bit platforms :)

> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
>  drivers/rtc/rtc-lib.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
> index e6bfb9c..459cd4d 100644
> --- a/drivers/rtc/rtc-lib.c
> +++ b/drivers/rtc/rtc-lib.c
> @@ -54,11 +54,11 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
>  {
>  	unsigned int month, year;
>  	unsigned long secs;
> -	int days;
> +	time64_t days;
>  
>  	/* time must be positive */
>  	days = div_s64(time, 86400);
> -	secs = time - (unsigned int) days * 86400;
> +	secs = time - days * 86400;
>  
>  	/* day of the week, 1970-01-01 was a Thursday */
>  	tm->tm_wday = (days + 4) % 7;
> -- 
> 1.7.10.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
  2015-12-04  1:55 ` Alexandre Belloni
@ 2015-12-04  2:06   ` Sasha Levin
  0 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2015-12-04  2:06 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: a.zummo, rtc-linux, linux-kernel

On 12/03/2015 08:55 PM, Alexandre Belloni wrote:
> On 03/12/2015 at 19:12:24 -0500, Sasha Levin wrote :
>> > 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().
>> > 
> And at that time, the robots won't care about 32bit platforms :)

One can only hope... :)

I'll resend.


Thanks,
Sasha

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-04  2:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-04  0:12 [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Sasha Levin
2015-12-04  0:21 ` kbuild test robot
2015-12-04  1:39 ` kbuild test robot
2015-12-04  1:41 ` kbuild test robot
2015-12-04  1:55 ` Alexandre Belloni
2015-12-04  2:06   ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox