Commit e3d5a27d5862b6425d0879272e24abecf7245105

Authored by Paul Mackerras
Committed by Linus Torvalds
1 parent af9379c712

Allow times and time system calls to return small negative values

At the moment, the times() system call will appear to fail for a period
shortly after boot, while the value it want to return is between -4095 and
-1.  The same thing will also happen for the time() system call on 32-bit
platforms some time in 2106 or so.

On some platforms, such as x86, this is unavoidable because of the system
call ABI, but other platforms such as powerpc have a separate error
indication from the return value, so system calls can in fact return small
negative values without indicating an error.  On those platforms,
force_successful_syscall_return() provides a way to indicate that the
system call return value should not be treated as an error even if it is
in the range which would normally be taken as a negative error number.

This adds a force_successful_syscall_return() call to the time() and
times() system calls plus their 32-bit compat versions, so that they don't
erroneously indicate an error on those platforms whose system call ABI has
a separate error indication.  This will not affect anything on other
platforms.

Joakim Tjernlund added the fix for time() and the compat versions of
time() and times(), after I did the fix for times().

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 9 additions and 2 deletions Side-by-side Diff

... ... @@ -24,6 +24,7 @@
24 24 #include <linux/migrate.h>
25 25 #include <linux/posix-timers.h>
26 26 #include <linux/times.h>
  27 +#include <linux/ptrace.h>
27 28  
28 29 #include <asm/uaccess.h>
29 30  
... ... @@ -229,6 +230,7 @@
229 230 if (copy_to_user(tbuf, &tmp, sizeof(tmp)))
230 231 return -EFAULT;
231 232 }
  233 + force_successful_syscall_return();
232 234 return compat_jiffies_to_clock_t(jiffies);
233 235 }
234 236  
235 237  
... ... @@ -894,8 +896,9 @@
894 896  
895 897 if (tloc) {
896 898 if (put_user(i,tloc))
897   - i = -EFAULT;
  899 + return -EFAULT;
898 900 }
  901 + force_successful_syscall_return();
899 902 return i;
900 903 }
901 904  
... ... @@ -33,6 +33,7 @@
33 33 #include <linux/task_io_accounting_ops.h>
34 34 #include <linux/seccomp.h>
35 35 #include <linux/cpu.h>
  36 +#include <linux/ptrace.h>
36 37  
37 38 #include <linux/compat.h>
38 39 #include <linux/syscalls.h>
... ... @@ -927,6 +928,7 @@
927 928 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
928 929 return -EFAULT;
929 930 }
  931 + force_successful_syscall_return();
930 932 return (long) jiffies_64_to_clock_t(get_jiffies_64());
931 933 }
932 934  
... ... @@ -37,6 +37,7 @@
37 37 #include <linux/fs.h>
38 38 #include <linux/slab.h>
39 39 #include <linux/math64.h>
  40 +#include <linux/ptrace.h>
40 41  
41 42 #include <asm/uaccess.h>
42 43 #include <asm/unistd.h>
43 44  
... ... @@ -65,8 +66,9 @@
65 66  
66 67 if (tloc) {
67 68 if (put_user(i,tloc))
68   - i = -EFAULT;
  69 + return -EFAULT;
69 70 }
  71 + force_successful_syscall_return();
70 72 return i;
71 73 }
72 74