Fix for settimeofday() error checking regression
Subsystems (3)
cover Fix for settimeofday() error checking regression
As reported by Mika Westerberg here:
https://lkml.org/lkml/2016/5/30/413
A regression in the settimeofday error checking snuck in via 86d3473224b0 ("time: Introduce do_sys_settimeofday64()"), effecting cases where the timeval is null but the timezone was set.
This patchset contains my proposed fix and an addition to the kselftests to add checks for this case.
Testing/feedback would be greatly appreciated!
thanks
-john
John Stultz (2):
time: Fix problematic change in settimeofday error checking
kselftests: timers: Add set-tz test case
include/linux/timekeeping.h | 3 + tools/testing/selftests/timers/Makefile | 3 +- tools/testing/selftests/timers/set-tz.c | 119 ++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/set-tz.c
Signature · 1 line
1.9.1
RFC PATCH 1/2 time: Fix problematic change in settimeofday error checking
In commit 86d3473224b0 ("time: Introduce do_sys_settimeofday64()") some of the checking for a valid timeval was subtley changed which caused -EINVAL to be returned whenever the timeval was null.
However, it is possible to set the timezone data while specifying a NULL timeval, which is usually done to handle systems where the RTC keeps local time instead of UTC. Thus the patch causes such systems to have the time incorrectly set.
This patch addresses the issue by handling the error conditionals in the same way as was done previously.
--- include/linux/timekeeping.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/timekeeping.h +3 -0
@@ -21,6 +21,9 @@ static inline int do_sys_settimeofday(const struct timespec *tv,struct timespec64 ts64;if (!tv) +return do_sys_settimeofday64 (NULL , tz); + +if (tv && !timespec_valid (tv))return -EINVAL ; ts64 =timespec_to_timespec64 (*tv);
Signature · 1 line
1.9.1
Re: [RFC][PATCH 1/2] time: Fix problematic change in settimeofday error checking
include/linux/timekeeping.h static inline int do_sys_settimeofday(const struct timespec *tv, · line 27
Quoted 8 lines
include/linux/timekeeping.h +3
-0@@ -21,6 +21,9 @@ static inline int do_sys_settimeofday(const struct timespec *tv,struct timespec64 ts64;if (!tv) +return do_sys_settimeofday64 (NULL , tz); + +if (tv && !timespec_valid (tv))return -EINVAL ;
Looks like an extra check for (tv), maybe it will be better to use:
+ if (!timespec_valid(tv))
Regards, Dima.
Re: [RFC][PATCH 1/2] time: Fix problematic change in settimeofday error checking
In reply to John StultzQuoted 12 lines · John Stultz
In commit
86d3473224b0("time: Introducedo_sys_settimeofday64()") some of the checking for a valid timeval was subtley changed which caused-EINVALto be returned whenever the timeval was null.However, it is possible to set the timezone data while specifying a NULL timeval, which is usually done to handle systems where the RTC keeps local time instead of UTC. Thus the patch causes such systems to have the time incorrectly set.
This patch addresses the issue by handling the error conditionals in the same way as was done previously.
Quoted 9 lines
Cc Mika Westerberg <[email protected]>Cc Baolin Wang <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Shuah Khan <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Ingo Molnar <[email protected]>Cc Richard Cochran <[email protected]>Cc Prarit Bhargava <[email protected]>Reported-by Mika Westerberg <[email protected]>
I can confirm that this patch fixes the issue I'm seeing. Thanks!
RFC PATCH 2/2 kselftests: timers: Add set-tz test case
In reply to John StultzMika Westerberg reported a erroneous change in the error checking of settimeofday, so I wanted to add a test to ensure we don't trip over this again.
--- tools/testing/selftests/timers/Makefile | 3 +- tools/testing/selftests/timers/set-tz.c | 119 ++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/set-tz.c
tools/testing/selftests/timers/Makefile +2 -1
@@ -10,7 +10,7 @@ TEST_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ TEST_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ skew_consistency clocksource-switch leap-a-day \ - leapcrash set-tai set-2038 + leapcrash set-tai set-2038 set-tz bins = $(TEST_PROGS) $(TEST_PROGS_EXTENDED)
@@ -30,6 +30,7 @@ run_destructive_tests: run_tests ./clocksource-switch ./leap-a-day -s -i 10 ./leapcrash + ./set-tz ./set-tai ./set-2038
tools/testing/selftests/timers/set-tz.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.9.1