rtc: add century field data boundary
Subsystems (2)
PATCH 1/1 rtc: add century field data boundary
According to ACPI specification, the century field data should be ranged 0-63. so if it's over this range, it could cause system RTC settings error including alarmwakeup settings. So it's required to have this boundary for safe RTC init settings.
--- arch/x86/kernel/rtc.c | 7 +++++-- drivers/rtc/rtc-mc146818-lib.c | 7 +++++-- include/linux/mc146818rtc.h | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-)
arch/x86/kernel/rtc.c +5 -2
@@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)#ifdef CONFIG_ACPI if (acpi_gbl_FADT.header.revision >=FADT2_REVISION_ID && - acpi_gbl_FADT.century) - century =CMOS_READ (acpi_gbl_FADT.century); + acpi_gbl_FADT.century) { +if ((century =CMOS_READ (acpi_gbl_FADT.century)) > +RTC_CENTURY_LIMIT ) + century =0 ; + }#endif status =CMOS_READ (RTC_CONTROL );
drivers/rtc/rtc-mc146818-lib.c +5 -2
@@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time *time)#endif #ifdef CONFIG_ACPI if (acpi_gbl_FADT.header.revision >=FADT2_REVISION_ID && - acpi_gbl_FADT.century) - century =CMOS_READ (acpi_gbl_FADT.century); + acpi_gbl_FADT.century) { +if ((century =CMOS_READ (acpi_gbl_FADT.century)) > +RTC_CENTURY_LIMIT ) + century =0 ; + }#endif ctrl =CMOS_READ (RTC_CONTROL );spin_unlock_irqrestore (&rtc_lock, flags);
include/linux/mc146818rtc.h +2 -0
@@ -122,6 +122,8 @@ struct cmos_rtc_board_info {#define RTC_IO_EXTENT_USED RTC_IO_EXTENT#endif /* ARCH_RTC_LOCATION */ +#define RTC_CENTURY_LIMIT 0x3F +unsigned int mc146818_get_time (struct rtc_time *time);int mc146818_set_time (struct rtc_time *time);
Signature · 1 line
1.9.1
Quoted 17 lines · Andrew Kim
According to ACPI specification, the century field data should be ranged 0-63. so if it's over this range, it could cause system RTC settings error including alarmwakeup settings. So it's required to have this boundary for safe RTC init settings.
Signed-off-by Andrew Kim <[email protected]>--- arch/x86/kernel/rtc.c | 7 +++++-- drivers/rtc/rtc-mc146818-lib.c | 7 +++++-- include/linux/mc146818rtc.h | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-)arch/x86/kernel/rtc.c +0
-0
arch/x86/kernel/rtc.c void mach_get_cmos_time(struct timespec *now) · line 89
Quoted 8 lines
arch/x86/kernel/rtc.c +3
-2@@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)#ifdef CONFIG_ACPI if (acpi_gbl_FADT.header.revision >=FADT2_REVISION_ID && - acpi_gbl_FADT.century) - century =CMOS_READ (acpi_gbl_FADT.century); + acpi_gbl_FADT.century) { +if ((century =CMOS_READ (acpi_gbl_FADT.century)) > +RTC_CENTURY_LIMIT )
Please don't combine assignments and comparisons into a single statement (especially for non-NULL comparisons), i.e. use
century = CMOS_READ(acpi_gbl_FADT.century);
if (century > RTC_CENTURY_LIMIT) {
...Quoted 10 lines
arch/x86/kernel/rtc.c +2
-0+ century = 0; + }#endif status =CMOS_READ (RTC_CONTROL );drivers/rtc/rtc-mc146818-lib.c +0
-0
drivers/rtc/rtc-mc146818-lib.c unsigned int mc146818_get_time(struct rtc_time *time) · line 66
Quoted 8 lines
drivers/rtc/rtc-mc146818-lib.c +3
-2@@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time *time)#endif #ifdef CONFIG_ACPI if (acpi_gbl_FADT.header.revision >=FADT2_REVISION_ID && - acpi_gbl_FADT.century) - century =CMOS_READ (acpi_gbl_FADT.century); + acpi_gbl_FADT.century) { +if ((century =CMOS_READ (acpi_gbl_FADT.century)) > +RTC_CENTURY_LIMIT )
Likewise
drivers/rtc/rtc-mc146818-lib.c unsigned int mc146818_get_time(struct rtc_time *time) · line 69
Quoted 3 lines
drivers/rtc/rtc-mc146818-lib.c +2
-0+ century = 0; + }#endif
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Thanks for the comments, let me follow this.
BRs
Andrew
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Geert Uytterhoeven
Sent: Wednesday, October 05, 2016 12:03 AM
To: Kim, Andrew
Cc: [email protected]
Subject: Re: [PATCH 1/1] rtc: add century field data boundary
Quoted 17 lines · Andrew Kim
According to ACPI specification, the century field data should be ranged 0-63. so if it's over this range, it could cause system RTC settings error including alarmwakeup settings.
So it's required to have this boundary for safe RTC init settings.Signed-off-by Andrew Kim <[email protected]>--- arch/x86/kernel/rtc.c | 7 +++++-- drivers/rtc/rtc-mc146818-lib.c | 7 +++++-- include/linux/mc146818rtc.h | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-)arch/x86/kernel/rtc.c index renamed from arch/x86/kernel/rtc.c +0
-079c6311c..feac180 100644
arch/x86/kernel/rtc.c void mach_get_cmos_time(struct timespec *now) · line 89
Quoted 8 lines
arch/x86/kernel/rtc.c +3
-2@@ -84,8 +84,11 @@ void mach_get_cmos_time(struct timespec *now)#ifdef CONFIG_ACPI if (acpi_gbl_FADT.header.revision >=FADT2_REVISION_ID && - acpi_gbl_FADT.century) - century =CMOS_READ (acpi_gbl_FADT.century); + acpi_gbl_FADT.century) { +if ((century =CMOS_READ (acpi_gbl_FADT.century)) > +RTC_CENTURY_LIMIT )
Please don't combine assignments and comparisons into a single statement (especially for non-NULL comparisons), i.e. use
century = CMOS_READ(acpi_gbl_FADT.century);
if (century > RTC_CENTURY_LIMIT) {
...Quoted 10 lines
arch/x86/kernel/rtc.c +2
-0+ century =0 ; + }#endif status = CMOS_READ(RTC_CONTROL); diff --git
a/drivers/rtc/rtc-mc146818-lib.cb/drivers/rtc/rtc-mc146818-lib.cindex 2f1772a..1d83c2c 100644
drivers/rtc/rtc-mc146818-lib.c unsigned int mc146818_get_time(struct rtc_time · line 65
Quoted 7 lines
drivers/rtc/rtc-mc146818-lib.c +3
-2@@ -61,8 +61,11 @@ unsigned int mc146818_get_time(struct rtc_time *time) #endif #ifdef CONFIG_ACPIif (acpi_gbl_FADT.header.revision >=FADT2_REVISION_ID && - acpi_gbl_FADT.century) - century =CMOS_READ (acpi_gbl_FADT.century); + acpi_gbl_FADT.century) { +if ((century =CMOS_READ (acpi_gbl_FADT.century)) > +RTC_CENTURY_LIMIT )
Likewise
drivers/rtc/rtc-mc146818-lib.c unsigned int mc146818_get_time(struct rtc_time · line 68
Quoted 3 lines
drivers/rtc/rtc-mc146818-lib.c +2
-0+ century = 0; + }#endif
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds