Skip to contentSkip to conversation

rtc: add century field data boundary

PATCH Alexandre Belloni 1 participant 1 message Oct 19, 2016 1 message not in the archive Real time clock (RTC)

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi,

You should probably copy the x86 maintainers as part of that patch touches code for that architecture.

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.

---
 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
index 79c6311c..feac180 100644

arch/x86/kernel/rtc.c void mach_get_cmos_time(struct timespec *now) · line 88

Quoted 7 lines
arch/x86/kernel/rtc.c +2 -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)) >

checkpatch complains about using an assignment in an if() which I find justifiable. Can you change that?

Quoted 40 lines
arch/x86/kernel/rtc.c +3 -0
+			RTC_CENTURY_LIMIT)
+			century = 0;
+	}
 #endif
 
 	status = CMOS_READ(RTC_CONTROL);
drivers/rtc/rtc-mc146818-lib.c +5 -2
index 2f1772a..1d83c2c 100644
@@ -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
index a585b4b..199065a 100644
@@ -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
Signature · 3 lines
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com