Commit 2d602bf2 authored by Arnd Bergmann's avatar Arnd Bergmann

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: default avatarArnd Bergmann <arnd@arndb.de>
parent 853bc0ab
...@@ -49,6 +49,7 @@ struct acct ...@@ -49,6 +49,7 @@ struct acct
__u16 ac_uid16; /* LSB of Real User ID */ __u16 ac_uid16; /* LSB of Real User ID */
__u16 ac_gid16; /* LSB of Real Group ID */ __u16 ac_gid16; /* LSB of Real Group ID */
__u16 ac_tty; /* Control Terminal */ __u16 ac_tty; /* Control Terminal */
/* __u32 range means times from 1970 to 2106 */
__u32 ac_btime; /* Process Creation Time */ __u32 ac_btime; /* Process Creation Time */
comp_t ac_utime; /* User Time */ comp_t ac_utime; /* User Time */
comp_t ac_stime; /* System Time */ comp_t ac_stime; /* System Time */
...@@ -81,6 +82,7 @@ struct acct_v3 ...@@ -81,6 +82,7 @@ struct acct_v3
__u32 ac_gid; /* Real Group ID */ __u32 ac_gid; /* Real Group ID */
__u32 ac_pid; /* Process ID */ __u32 ac_pid; /* Process ID */
__u32 ac_ppid; /* Parent Process ID */ __u32 ac_ppid; /* Parent Process ID */
/* __u32 range means times from 1970 to 2106 */
__u32 ac_btime; /* Process Creation Time */ __u32 ac_btime; /* Process Creation Time */
#ifdef __KERNEL__ #ifdef __KERNEL__
__u32 ac_etime; /* Elapsed Time */ __u32 ac_etime; /* Elapsed Time */
......
...@@ -112,6 +112,7 @@ struct taskstats { ...@@ -112,6 +112,7 @@ struct taskstats {
__u32 ac_gid; /* Group ID */ __u32 ac_gid; /* Group ID */
__u32 ac_pid; /* Process ID */ __u32 ac_pid; /* Process ID */
__u32 ac_ppid; /* Parent process ID */ __u32 ac_ppid; /* Parent process ID */
/* __u32 range means times from 1970 to 2106 */
__u32 ac_btime; /* Begin time [sec since 1970] */ __u32 ac_btime; /* Begin time [sec since 1970] */
__u64 ac_etime __attribute__((aligned(8))); __u64 ac_etime __attribute__((aligned(8)));
/* Elapsed time [usec] */ /* Elapsed time [usec] */
......
...@@ -416,6 +416,7 @@ static void fill_ac(acct_t *ac) ...@@ -416,6 +416,7 @@ static void fill_ac(acct_t *ac)
{ {
struct pacct_struct *pacct = &current->signal->pacct; struct pacct_struct *pacct = &current->signal->pacct;
u64 elapsed, run_time; u64 elapsed, run_time;
time64_t btime;
struct tty_struct *tty; struct tty_struct *tty;
/* /*
...@@ -448,7 +449,8 @@ static void fill_ac(acct_t *ac) ...@@ -448,7 +449,8 @@ static void fill_ac(acct_t *ac)
} }
#endif #endif
do_div(elapsed, AHZ); do_div(elapsed, AHZ);
ac->ac_btime = get_seconds() - elapsed; btime = ktime_get_real_seconds() - elapsed;
ac->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX);
#if ACCT_VERSION==2 #if ACCT_VERSION==2
ac->ac_ahz = AHZ; ac->ac_ahz = AHZ;
#endif #endif
......
...@@ -24,6 +24,7 @@ void bacct_add_tsk(struct user_namespace *user_ns, ...@@ -24,6 +24,7 @@ void bacct_add_tsk(struct user_namespace *user_ns,
const struct cred *tcred; const struct cred *tcred;
u64 utime, stime, utimescaled, stimescaled; u64 utime, stime, utimescaled, stimescaled;
u64 delta; u64 delta;
time64_t btime;
BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);
...@@ -32,9 +33,10 @@ void bacct_add_tsk(struct user_namespace *user_ns, ...@@ -32,9 +33,10 @@ void bacct_add_tsk(struct user_namespace *user_ns,
/* Convert to micro seconds */ /* Convert to micro seconds */
do_div(delta, NSEC_PER_USEC); do_div(delta, NSEC_PER_USEC);
stats->ac_etime = delta; stats->ac_etime = delta;
/* Convert to seconds for btime */ /* Convert to seconds for btime (note y2106 limit) */
do_div(delta, USEC_PER_SEC); btime = ktime_get_real_seconds() - div_u64(delta, USEC_PER_SEC);
stats->ac_btime = get_seconds() - delta; stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX);
if (thread_group_leader(tsk)) { if (thread_group_leader(tsk)) {
stats->ac_exitcode = tsk->exit_code; stats->ac_exitcode = tsk->exit_code;
if (tsk->flags & PF_FORKNOEXEC) if (tsk->flags & PF_FORKNOEXEC)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment