Skip to contentSkip to conversation

Fix for settimeofday() error checking regression

PATCH In review John Stultz 3 participants 5 messages Jun 1, 2016 – Jun 2, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 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.

Thomas: Can you please queue the first patch in tip/timers/urgent?

Shuah: I'll leave the second patch to your discretion.

thanks
-john

v2:
* Add logic simplification suggested by Dima Stepanov
* Add tested by tag from Mika

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]>

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
#1 lore raw

PATCH v2 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.

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]>

---
v2: Add logic simplification from Dima Stepanov <[email protected]>

 include/linux/timekeeping.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/timekeeping.h +3 -0
index 37dbacf..816b754 100644
@@ -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 (!timespec_valid(tv))
 		return -EINVAL;
 
 	ts64 = timespec_to_timespec64(*tv);
Signature · 1 line
1.9.1
#2 lore raw

[tip:timers/urgent] time: Make settimeofday error checking work again

time: Make settimeofday error checking work again
Commit-ID:  dfc2507b26af22b0bbc85251b8545b36d8bc5d72
Gitweb:     http://git.kernel.org/tip/dfc2507b26af22b0bbc85251b8545b36d8bc5d72
Author:     John Stultz <[email protected]>
AuthorDate: Wed, 1 Jun 2016 11:53:26 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Wed, 1 Jun 2016 21:13:43 +0200

time: Make settimeofday error checking work again

In commit 86d3473224b0 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.

Fixes 86d3473224b0 "time: Introduce do_sys_settimeofday64()"
Cc Prarit Bhargava <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Richard Cochran <[email protected]>
Cc Shuah Khan <[email protected]>
---
 include/linux/timekeeping.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/timekeeping.h +3 -0
index 37dbacf..816b754 100644
@@ -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 (!timespec_valid(tv))
 		return -EINVAL;
 
 	ts64 = timespec_to_timespec64(*tv);
#3 lore raw

PATCH v2 2/2 kselftests: timers: Add set-tz test case

In reply to John Stultz

Mika 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.

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]>
---
 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
index 4a1be1b..1d55568 100644
@@ -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
#4 lore raw

Re: [PATCH 2/2] kselftests: timers: Add set-tz test case

Quoted 13 lines · John Stultz

Mika 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.

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]>
Quoted 1 line

---

Makes sense to get this into 4.7. Applied to linux-kselftest fixes. I will get this into rc-2 or rc-3.

thanks,
-- Shuah