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

acct: stop using get_seconds()

In 'struct acct', 'struct acct_v3', and 'struct taskstats' we have
a 32-bit 'ac_btime' field containing an absolute time value, which
will overflow in year 2106.

There are two possible ways to deal with it:

a) let it overflow and have user space code deal with reconstructing
the data based on the current time, or
b) truncate the times based on the range of the u32 type.

Neither of them solves the actual problem. Pick the second
one to best document what the issue is, and have someone
fix it in a future version.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+11 -4
+2
include/uapi/linux/acct.h
··· 49 49 __u16 ac_uid16; /* LSB of Real User ID */ 50 50 __u16 ac_gid16; /* LSB of Real Group ID */ 51 51 __u16 ac_tty; /* Control Terminal */ 52 + /* __u32 range means times from 1970 to 2106 */ 52 53 __u32 ac_btime; /* Process Creation Time */ 53 54 comp_t ac_utime; /* User Time */ 54 55 comp_t ac_stime; /* System Time */ ··· 82 81 __u32 ac_gid; /* Real Group ID */ 83 82 __u32 ac_pid; /* Process ID */ 84 83 __u32 ac_ppid; /* Parent Process ID */ 84 + /* __u32 range means times from 1970 to 2106 */ 85 85 __u32 ac_btime; /* Process Creation Time */ 86 86 #ifdef __KERNEL__ 87 87 __u32 ac_etime; /* Elapsed Time */
+1
include/uapi/linux/taskstats.h
··· 112 112 __u32 ac_gid; /* Group ID */ 113 113 __u32 ac_pid; /* Process ID */ 114 114 __u32 ac_ppid; /* Parent process ID */ 115 + /* __u32 range means times from 1970 to 2106 */ 115 116 __u32 ac_btime; /* Begin time [sec since 1970] */ 116 117 __u64 ac_etime __attribute__((aligned(8))); 117 118 /* Elapsed time [usec] */
+3 -1
kernel/acct.c
··· 416 416 { 417 417 struct pacct_struct *pacct = &current->signal->pacct; 418 418 u64 elapsed, run_time; 419 + time64_t btime; 419 420 struct tty_struct *tty; 420 421 421 422 /* ··· 449 448 } 450 449 #endif 451 450 do_div(elapsed, AHZ); 452 - ac->ac_btime = get_seconds() - elapsed; 451 + btime = ktime_get_real_seconds() - elapsed; 452 + ac->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX); 453 453 #if ACCT_VERSION==2 454 454 ac->ac_ahz = AHZ; 455 455 #endif
+5 -3
kernel/tsacct.c
··· 24 24 const struct cred *tcred; 25 25 u64 utime, stime, utimescaled, stimescaled; 26 26 u64 delta; 27 + time64_t btime; 27 28 28 29 BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); 29 30 ··· 33 32 /* Convert to micro seconds */ 34 33 do_div(delta, NSEC_PER_USEC); 35 34 stats->ac_etime = delta; 36 - /* Convert to seconds for btime */ 37 - do_div(delta, USEC_PER_SEC); 38 - stats->ac_btime = get_seconds() - delta; 35 + /* Convert to seconds for btime (note y2106 limit) */ 36 + btime = ktime_get_real_seconds() - div_u64(delta, USEC_PER_SEC); 37 + stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX); 38 + 39 39 if (thread_group_leader(tsk)) { 40 40 stats->ac_exitcode = tsk->exit_code; 41 41 if (tsk->flags & PF_FORKNOEXEC)