[U-Boot] [PATCH 0/3] efi_loader: parameter checks in SetTime()

The UEFI spec requires to check the validity of the time stamp passed to SetTime().
For the runtime version of SetTime() defined a weak implementation. Put the definition into include/efi_loader.h to make it available to implementors.
Heinrich Schuchardt (3): rtc: export rtc_month_days() efi_loader: check time in SetTime() efi_loader: export efi_set_time()
drivers/rtc/rtc-lib.c | 2 +- include/efi_loader.h | 2 ++ include/rtc.h | 8 ++++++++ lib/efi_loader/efi_runtime.c | 22 +++++++++++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-)
-- 2.20.1

Export function rtc_month_days() for reuse in the UEFI subsystem.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- drivers/rtc/rtc-lib.c | 2 +- include/rtc.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index 6528ddfebb..1f7bdade29 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -23,7 +23,7 @@ static const unsigned char rtc_days_in_month[] = { /* * The number of days in the month. */ -static int rtc_month_days(unsigned int month, unsigned int year) +int rtc_month_days(unsigned int month, unsigned int year) { return rtc_days_in_month[month] + (is_leap_year(year) && month == 1); } diff --git a/include/rtc.h b/include/rtc.h index 2c3a5743e3..b255bdc7a3 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -258,4 +258,12 @@ void rtc_to_tm(u64 time_t, struct rtc_time *time); */ unsigned long rtc_mktime(const struct rtc_time *time);
+/** + * rtc_month_days() - The number of days in the month + * + * @month: month (January = 0) + * @year: year (4 digits) + */ +int rtc_month_days(unsigned int month, unsigned int year); + #endif /* _RTC_H_ */ -- 2.20.1

The UEFI spec prescribes that we check that the timestamp passed to SetTime() is checked for validity.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- lib/efi_loader/efi_runtime.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 058b40a887..668e380664 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -214,6 +214,26 @@ out: #endif }
+/** + * efi_validate_time() - checks if timestamp is valid + * + * @time: timestamp to validate + * Returns: 0 if timestamp is valid, 1 otherwise + */ +static int efi_validate_time(struct efi_time *time) +{ + return (!time || + time->year < 1900 || time->year > 9999 || + !time->month || time->month > 12 || !time->day || + time->day > rtc_month_days(time->month - 1, time->year) || + time->hour > 23 || time->minute > 59 || time->second > 59 || + time->nanosecond > 999999999 || + time->daylight & + ~(EFI_TIME_IN_DAYLIGHT | EFI_TIME_ADJUST_DAYLIGHT) || + ((time->timezone < -1440 || time->timezone > 1440) && + time->timezone != EFI_UNSPECIFIED_TIMEZONE)); +} + /** * efi_set_time_boottime() - set current time * @@ -235,7 +255,7 @@ static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time)
EFI_ENTRY("%p", time);
- if (!time) { + if (efi_validate_time(time)) { ret = EFI_INVALID_PARAMETER; goto out; } -- 2.20.1

To let a board implement the runtime version of SetTime() we have to provide the definition of the weak function in an include.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- include/efi_loader.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/efi_loader.h b/include/efi_loader.h index 77b2f60bdc..23ce732267 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -594,6 +594,8 @@ efi_status_t __efi_runtime EFIAPI efi_get_time( struct efi_time *time, struct efi_time_cap *capabilities);
+efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time); + #ifdef CONFIG_CMD_BOOTEFI_SELFTEST /* * Entry point for the tests of the EFI API. -- 2.20.1
participants (1)
-
Heinrich Schuchardt