rtc: hctosys: Ensure system time doesn't overflow time_t
Subsystems (2)
Alexandre Belloni
maintainerPATCH 1/6 rtc: hctosys: Ensure system time doesn't overflow time_t
On 32bit platforms, time_t is still a signed 32bit long. If it is overflowed, userspace and the kernel cant agree on the current system time. This causes multiple issues, in particular with systemd:
https://github.com/systemd/systemd/issues/1143
A good workaround is to simply avoid using systohc which is something I greatly encourage as the time is better set by userspace.
However, many distribution enable it and use systemd which is rendering the system unusable in case the RTC holds a date after 2038 (and more so after 2106). Many drivers have workaround for this case and they should be eliminated so there is only one place left to fix when userspace is able to cope with dates after the 31bit overflow.
--- drivers/rtc/hctosys.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/rtc/hctosys.c +5 -0
@@ -49,6 +49,11 @@ static int __init rtc_hctosys(void) tv64.tv_sec =rtc_tm_to_time64 (&tm); +#if BITS_PER_LONG ==32 +if (tv64.tv_sec >INT_MAX ) + goto err_read; +#endif + err =do_settimeofday64 (&tv64); dev_info(rtc->dev.parent,
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 2/6 rtc: mv: remove artificial limitation
Dates after 2038 actually fit on 32 bits. The counter will overflow in 2106. Also, it is bad practice to reset the RTC to a default value.
--- drivers/rtc/rtc-mv.c | 12 ------------ 1 file changed, 12 deletions(-)
drivers/rtc/rtc-mv.c +0 -12
@@ -223,7 +223,6 @@ static int __init mv_rtc_probe(struct platform_device *pdev)struct resource *res;struct rtc_plat_data *pdata;u32 rtc_time; -u32 rtc_date;int ret =0 ; pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL );
@@ -259,17 +258,6 @@ static int __init mv_rtc_probe(struct platform_device *pdev) } } -/* -* A date after January 19th, 2038 does not fit on 32 bits and -* will confuse the kernel and userspace. Reset to a sane date -* (January 1st, 2013) if we're after 2038. -*/ - rtc_date =readl (pdata->ioaddr +RTC_DATE_REG_OFFS ); -if (bcd2bin ((rtc_date >>RTC_YEAR_OFFS ) &0xff ) >=38 ) { -dev_info (&pdev->dev,"invalid RTC date, resetting to January 1st, 2013\n" ); -writel (0x130101 , pdata->ioaddr +RTC_DATE_REG_OFFS ); - } - pdata->irq =platform_get_irq (pdev,0 );platform_set_drvdata (pdev, pdata);
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 3/6 rtc: mrst: remove artificial limitation
In reply to Alexandre BelloniThe hardware supports years up to 100 so don't limit the year to 2038 artificially.
--- drivers/rtc/rtc-mrst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-mrst.c +1 -1
@@ -122,7 +122,7 @@ static int mrst_set_time(struct device *dev, struct rtc_time *time) min = time->tm_min; sec = time->tm_sec; -if (yrs <72 || yrs >138 ) +if (yrs <72 || yrs >172 )return -EINVAL ; yrs -=72 ;
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 4/6 rtc: st-lpc: remove artificial limitation
In reply to Alexandre BelloniThe LPC RTC supports dates way beyond 2038, don't limit it artificially as the kernel handles dates after 2038 properly.
--- drivers/rtc/rtc-st-lpc.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/rtc/rtc-st-lpc.c +0 -15
@@ -254,21 +254,6 @@ static int st_rtc_probe(struct platform_device *pdev)platform_set_drvdata (pdev, rtc); -/* -* The RTC-LPC is able to manage date.year > 2038 -* but currently the kernel can not manage this date! -* If the RTC-LPC has a date.year > 2038 then -* it's set to the epoch "Jan 1st 2000" -*/ -st_rtc_read_time (&pdev->dev, &tm_check); - -if (tm_check.tm_year >= (2038 -1900 )) { -memset (&tm_check,0 ,sizeof (tm_check)); - tm_check.tm_year =100 ; - tm_check.tm_mday =1 ; -st_rtc_set_time (&pdev->dev, &tm_check); - } - rtc->rtc_dev =rtc_device_register ("st-lpc-rtc" , &pdev->dev, &st_rtc_ops,THIS_MODULE );if (IS_ERR (rtc->rtc_dev)) {
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 5/6 rtc: 88pm80x: remove artificial limitation
In reply to Alexandre BelloniThe 88pm80x supports time up to 2106 (it is a 32 bit counter). Also, the year will never be before 1970 as the RTC core forbids that.
--- drivers/rtc/rtc-88pm80x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-88pm80x.c +2 -2
@@ -134,9 +134,9 @@ static int pm80x_rtc_set_time(struct device *dev, struct rtc_time *tm)struct pm80x_rtc_info *info =dev_get_drvdata (dev);unsigned char buf[4 ];unsigned long ticks, base, data; -if ((tm->tm_year <70 ) || (tm->tm_year >138 )) { +if (tm->tm_year >206 ) {dev_dbg (info->dev, -"Set time %d out of range. Please set time between 1970 to 2038.\n" , +"Set time %d out of range. Please set time between 1970 to 2106.\n" ,1900 + tm->tm_year);return -EINVAL ; }
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 6/6 rtc: 88pm860x: remove artificial limitation
In reply to Alexandre BelloniThe 88pm860x supports time up to 2106 (it is a 32 bit counter). Also, the year will never be before 1970 as the RTC core forbids that.
--- drivers/rtc/rtc-88pm860x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-88pm860x.c +2 -2
@@ -135,9 +135,9 @@ static int pm860x_rtc_set_time(struct device *dev, struct rtc_time *tm)unsigned char buf[4 ];unsigned long ticks, base, data; -if ((tm->tm_year <70 ) || (tm->tm_year >138 )) { +if (tm->tm_year >206 ) {dev_dbg (info->dev,"Set time %d out of range. " -"Please set time between 1970 to 2038.\n" , +"Please set time between 1970 to 2106.\n" ,1900 + tm->tm_year);return -EINVAL ; }
Signature · 1 line
2.16.2