Skip to contentSkip to conversation

posix-timers: fix nanosleep_copyout() for CONFIG_COMPAT_32BIT_TIME

PATCH New Arnd Bergmann 2 participants 6 messages Jun 18, 2018 – Jun 19, 2018

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

PATCH 1/3 posix-timers: fix nanosleep_copyout() for CONFIG_COMPAT_32BIT_TIME

Commit b5793b0d92c9 ("posix-timers: Make compat syscalls depend on CONFIG_COMPAT_32BIT_TIME") added support for building the nanosleep compat system call on 32-bit architectures, but missed one change in nanosleep_copyout(), which would trigger a BUG() as soon as we switch any architecture over to use it.

This makes sure the TT_COMPAT handler is available when we need it.

---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
index 055a4a728c00..3e93c54bd3a1 100644
@@ -1659,7 +1659,7 @@ EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
 int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts)
 {
 	switch(restart->nanosleep.type) {
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_COMPAT_32BIT_TIME
 	case TT_COMPAT:
 		if (compat_put_timespec64(ts, restart->nanosleep.compat_rmtp))
 			return -EFAULT;
Signature · 1 line
2.9.0
#1 lore raw

PATCH 2/3 time: use ktime_get_real_seconds() in time syscall

Both get_seconds() and do_gettimeofday() are deprecated. Let's change the time() implementation to use the replacement function instead.

Obviously the system call will still overflow in 2038, but this gets us closer to removing the old helper functions.

---
 kernel/time/time.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/time/time.c +2 -4
index 8e4f3fd2f84b..90867ece5c09 100644
@@ -63,7 +63,7 @@ EXPORT_SYMBOL(sys_tz);
  */
 SYSCALL_DEFINE1(time, time_t __user *, tloc)
 {
-	time_t i = get_seconds();
+	time_t i = (time_t)ktime_get_real_seconds();
 
 	if (tloc) {
 		if (put_user(i,tloc))
@@ -106,11 +106,9 @@ SYSCALL_DEFINE1(stime, time_t __user *, tptr)
 /* compat_time_t is a 32 bit "long" and needs to get converted. */
 COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
 {
-	struct timeval tv;
 	compat_time_t i;
 
-	do_gettimeofday(&tv);
-	i = tv.tv_sec;
+	i = (compat_time_t)ktime_get_real_seconds();
 
 	if (tloc) {
 		if (put_user(i,tloc))
Signature · 1 line
2.9.0
#2 lore raw

[tip:timers/core] time: Use ktime_get_real_seconds() in time syscall

time: Use ktime_get_real_seconds() in time syscall
Commit-ID:  f5a89295e2f566d8e9f1d4f3d524d8d3c966958c
Gitweb:     https://git.kernel.org/tip/f5a89295e2f566d8e9f1d4f3d524d8d3c966958c
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Mon, 18 Jun 2018 16:08:00 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 19 Jun 2018 09:56:26 +0200

time: Use ktime_get_real_seconds() in time syscall

Both get_seconds() and do_gettimeofday() are deprecated. Change the time() implementation to use the replacement function instead.

Obviously the system call will still overflow in 2038, but this gets us closer to removing the old helper functions.

---
 kernel/time/time.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/time/time.c +2 -4
index 6fa99213fc72..b1225db61eb2 100644
@@ -63,7 +63,7 @@ EXPORT_SYMBOL(sys_tz);
  */
 SYSCALL_DEFINE1(time, time_t __user *, tloc)
 {
-	time_t i = get_seconds();
+	time_t i = (time_t)ktime_get_real_seconds();
 
 	if (tloc) {
 		if (put_user(i,tloc))
@@ -106,11 +106,9 @@ SYSCALL_DEFINE1(stime, time_t __user *, tptr)
 /* compat_time_t is a 32 bit "long" and needs to get converted. */
 COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
 {
-	struct timeval tv;
 	compat_time_t i;
 
-	do_gettimeofday(&tv);
-	i = tv.tv_sec;
+	i = (compat_time_t)ktime_get_real_seconds();
 
 	if (tloc) {
 		if (put_user(i,tloc))
#3 lore raw

PATCH 3/3 timekeeping: use ktime_get_real_ts64() instead of getnstimeofday64()

In reply to Arnd Bergmann

The two do the same, this moves all users to the newer name for consistency.

---
 kernel/time/ntp.c         | 6 +++---
 kernel/time/timekeeping.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/time/ntp.c +3 -3
index a09ded765f6c..10a79053e82f 100644
@@ -502,7 +502,7 @@ static void sched_sync_hw_clock(struct timespec64 now,
 {
 	struct timespec64 next;
 
-	getnstimeofday64(&next);
+	ktime_get_real_ts64(&next);
 	if (!fail)
 		next.tv_sec = 659;
 	else {
@@ -537,7 +537,7 @@ static void sync_rtc_clock(void)
 	if (!IS_ENABLED(CONFIG_RTC_SYSTOHC))
 		return;
 
-	getnstimeofday64(&now);
+	ktime_get_real_ts64(&now);
 
 	adjust = now;
 	if (persistent_clock_is_local)
@@ -591,7 +591,7 @@ static bool sync_cmos_clock(void)
 	 * Architectures are strongly encouraged to use rtclib and not
 	 * implement this legacy API.
 	 */
-	getnstimeofday64(&now);
+	ktime_get_real_ts64(&now);
 	if (rtc_tv_nsec_ok(-1 * target_nsec, &adjust, &now)) {
 		if (persistent_clock_is_local)
 			adjust.tv_sec -= (sys_tz.tz_minuteswest * 60);
kernel/time/timekeeping.c +1 -1
index 4786df904c22..77c436a0070b 100644
@@ -2310,7 +2310,7 @@ int do_adjtimex(struct timex *txc)
 			return ret;
 	}
 
-	getnstimeofday64(&ts);
+	ktime_get_real_ts64(&ts);
 
 	raw_spin_lock_irqsave(&timekeeper_lock, flags);
 	write_seqcount_begin(&tk_core.seq);
Signature · 1 line
2.9.0
#4 lore raw

[tip:timers/core] timekeeping: Use ktime_get_real_ts64() instead of getnstimeofday64()

timekeeping: Use ktime_get_real_ts64() instead of getnstimeofday64()
Commit-ID:  d30faff900e666f9a6395a159fdd353c02f5bed0
Gitweb:     https://git.kernel.org/tip/d30faff900e666f9a6395a159fdd353c02f5bed0
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Mon, 18 Jun 2018 16:08:01 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 19 Jun 2018 09:56:26 +0200

timekeeping: Use ktime_get_real_ts64() instead of getnstimeofday64()

The two do the same, this moves all users to the newer name for consistency.

---
 kernel/time/ntp.c         | 6 +++---
 kernel/time/timekeeping.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/time/ntp.c +3 -3
index a09ded765f6c..10a79053e82f 100644
@@ -502,7 +502,7 @@ static void sched_sync_hw_clock(struct timespec64 now,
 {
 	struct timespec64 next;
 
-	getnstimeofday64(&next);
+	ktime_get_real_ts64(&next);
 	if (!fail)
 		next.tv_sec = 659;
 	else {
@@ -537,7 +537,7 @@ static void sync_rtc_clock(void)
 	if (!IS_ENABLED(CONFIG_RTC_SYSTOHC))
 		return;
 
-	getnstimeofday64(&now);
+	ktime_get_real_ts64(&now);
 
 	adjust = now;
 	if (persistent_clock_is_local)
@@ -591,7 +591,7 @@ static bool sync_cmos_clock(void)
 	 * Architectures are strongly encouraged to use rtclib and not
 	 * implement this legacy API.
 	 */
-	getnstimeofday64(&now);
+	ktime_get_real_ts64(&now);
 	if (rtc_tv_nsec_ok(-1 * target_nsec, &adjust, &now)) {
 		if (persistent_clock_is_local)
 			adjust.tv_sec -= (sys_tz.tz_minuteswest * 60);
kernel/time/timekeeping.c +1 -1
index 4786df904c22..77c436a0070b 100644
@@ -2310,7 +2310,7 @@ int do_adjtimex(struct timex *txc)
 			return ret;
 	}
 
-	getnstimeofday64(&ts);
+	ktime_get_real_ts64(&ts);
 
 	raw_spin_lock_irqsave(&timekeeper_lock, flags);
 	write_seqcount_begin(&tk_core.seq);
#5 lore raw

[tip:timers/urgent] posix-timers: Fix nanosleep_copyout() for CONFIG_COMPAT_32BIT_TIME

In reply to Arnd Bergmann
posix-timers: Fix nanosleep_copyout() for CONFIG_COMPAT_32BIT_TIME
Commit-ID:  0fe2795516b9e1c59b58b02bdf8658698117ec4e
Gitweb:     https://git.kernel.org/tip/0fe2795516b9e1c59b58b02bdf8658698117ec4e
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Mon, 18 Jun 2018 16:07:59 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 19 Jun 2018 09:23:19 +0200

posix-timers: Fix nanosleep_copyout() for CONFIG_COMPAT_32BIT_TIME

Commit b5793b0d92c9 added support for building the nanosleep compat system call on 32-bit architectures, but missed one change in nanosleep_copyout(), which would trigger a BUG() as soon as any architecture is switched over to use it.

Use the proper config symbol to enable the code path.

Fixes Commit b5793b0d92c9 ("posix-timers: Make compat syscalls depend on CONFIG_COMPAT_32BIT_TIME")
Cc Anna-Maria Gleixner <[email protected]>
Cc Deepa Dinamani <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
index 055a4a728c00..3e93c54bd3a1 100644
@@ -1659,7 +1659,7 @@ EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
 int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts)
 {
 	switch(restart->nanosleep.type) {
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_COMPAT_32BIT_TIME
 	case TT_COMPAT:
 		if (compat_put_timespec64(ts, restart->nanosleep.compat_rmtp))
 			return -EFAULT;