Skip to contentSkip to conversation

posix-timers: Fix clock_adjtime to return timex data on success

PATCH Superseded Miroslav Lichvar 3 participants 5 messages Jan 10, 2013 – Jan 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 posix-timers: Fix clock_adjtime to return timex data on success

Copy the modified timex data back to the user also with positive return values. This fixes reading of the CLOCK_REALTIME timex data when the clock is in a non-zero state.

---
 kernel/posix-timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/posix-timers.c +1 -1
index 69185ae..10349d5 100644
@@ -997,7 +997,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
 
 	err = kc->clock_adj(which_clock, &ktx);
 
-	if (!err && copy_to_user(utx, &ktx, sizeof(ktx)))
+	if (err >= 0 && copy_to_user(utx, &ktx, sizeof(ktx)))
 		return -EFAULT;
 
 	return err;
Signature · 1 line
1.7.11.7
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Miroslav Lichvar

Copy the modified timex data back to the user also with positive return values. This fixes reading of the CLOCK_REALTIME timex data when the clock is in a non-zero state.

(Adding John Stultz on CC)

Quoted 20 lines
---
 kernel/posix-timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/posix-timers.c +1 -1
index 69185ae..10349d5 100644
@@ -997,7 +997,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
 
 	err = kc->clock_adj(which_clock, &ktx);
 
-	if (!err && copy_to_user(utx, &ktx, sizeof(ktx)))
+	if (err >= 0 && copy_to_user(utx, &ktx, sizeof(ktx)))
 		return -EFAULT;
 
 	return err;
Signature · 1 line
1.7.11.7
#2 lore raw
Quoted 9 lines · Richard Cochran
Quoted 5 lines · Miroslav Lichvar

Copy the modified timex data back to the user also with positive return values. This fixes reading of the CLOCK_REALTIME timex data when the clock is in a non-zero state.

(Adding John Stultz on CC)

Just to clarify (the commit message makes it pretty hard to understand exactly what's going wrong), this is to handle the case where clock_adj() returns a non-zero time_state value (such as TIME_INS) ?

thanks
-john

#3 lore raw

PATCH v2 1/1 posix-timers: Fix clock_adjtime to always return timex data on success

The clock_adj call returns the clock state on success, which may be a non-zero value (e.g. TIME_INS), but the modified timex data is copied back to the user only when zero value (TIME_OK) was returned. Fix the condition to copy the data also with positive return values.

---
 kernel/posix-timers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/posix-timers.c +1 -1
index 69185ae..10349d5 100644
@@ -997,7 +997,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
 
 	err = kc->clock_adj(which_clock, &ktx);
 
-	if (!err && copy_to_user(utx, &ktx, sizeof(ktx)))
+	if (err >= 0 && copy_to_user(utx, &ktx, sizeof(ktx)))
 		return -EFAULT;
 
 	return err;
Signature · 1 line
1.7.11.7
#4 lore raw

Re: [PATCHv2] posix-timers: Fix clock_adjtime to always return timex data on success

Quoted 6 lines · Miroslav Lichvar

The clock_adj call returns the clock state on success, which may be a non-zero value (e.g. TIME_INS), but the modified timex data is copied back to the user only when zero value (TIME_OK) was returned. Fix the condition to copy the data also with positive return values.

Thanks for the resend. I've got this in my queue for 3.9

thanks
-john