Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

y2038: rusage: use __kernel_old_timeval

There are two 'struct timeval' fields in 'struct rusage'.

Unfortunately the definition of timeval is now ambiguous when used in
user space with a libc that has a 64-bit time_t, and this also changes
the 'rusage' definition in user space in a way that is incompatible with
the system call interface.

While there is no good solution to avoid all ambiguity here, change
the definition in the kernel headers to be compatible with the kernel
ABI, using __kernel_old_timeval as an unambiguous base type.

In previous discussions, there was also a plan to add a replacement
for rusage based on 64-bit timestamps and nanosecond resolution,
i.e. 'struct __kernel_timespec'. I have patches for that as well,
if anyone thinks we should do that.

Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+5 -5
+1 -1
arch/alpha/kernel/osf_sys.c
··· 963 963 } 964 964 965 965 static inline long 966 - put_tv_to_tv32(struct timeval32 __user *o, struct timeval *i) 966 + put_tv_to_tv32(struct timeval32 __user *o, struct __kernel_old_timeval *i) 967 967 { 968 968 return copy_to_user(o, &(struct timeval32){ 969 969 .tv_sec = i->tv_sec,
+2 -2
include/uapi/linux/resource.h
··· 22 22 #define RUSAGE_THREAD 1 /* only the calling thread */ 23 23 24 24 struct rusage { 25 - struct timeval ru_utime; /* user time used */ 26 - struct timeval ru_stime; /* system time used */ 25 + struct __kernel_old_timeval ru_utime; /* user time used */ 26 + struct __kernel_old_timeval ru_stime; /* system time used */ 27 27 __kernel_long_t ru_maxrss; /* maximum resident set size */ 28 28 __kernel_long_t ru_ixrss; /* integral shared memory size */ 29 29 __kernel_long_t ru_idrss; /* integral unshared data size */
+2 -2
kernel/sys.c
··· 1763 1763 unlock_task_sighand(p, &flags); 1764 1764 1765 1765 out: 1766 - r->ru_utime = ns_to_timeval(utime); 1767 - r->ru_stime = ns_to_timeval(stime); 1766 + r->ru_utime = ns_to_kernel_old_timeval(utime); 1767 + r->ru_stime = ns_to_kernel_old_timeval(stime); 1768 1768 1769 1769 if (who != RUSAGE_CHILDREN) { 1770 1770 struct mm_struct *mm = get_task_mm(p);