History

y2038: elfcore: Use __kernel_old_timeval for process times

We store elapsed time for a crashed process in struct elf_prstatus using 'timeval' structures. Once glibc starts using 64-bit time_t, this becomes incompatible with the kernel's idea of timeval since the structure layout no longer matches on 32-bit architectures. This changes the definition of the elf_prstatus structure to use __kernel_old_timeval instead, which is hardcoded to the currently used binary layout. There is no risk of overflow in y2038 though, because the time values are all relative times, and can store up to 68 years of process elapsed time. There is a risk of applications breaking at build time when they use the new kernel headers and expect the type to be exactly 'timeval' rather than a structure that has the same fields as before. Those applications have to be modified to deal with 64-bit time_t anyway.

Arnd Bergmann committed 8 years ago

Commit e2bb80d1 parent 693737b6 files · +22 −22Browse files

Unified · Split

6 files
  1. arch/mips/kernel/binfmt_elfn32.c +2 −2
  2. arch/mips/kernel/binfmt_elfo32.c +2 −2
  3. fs/binfmt_elf.c +6 −6
  4. fs/binfmt_elf_fdpic.c +6 −6
  5. fs/compat_binfmt_elf.c +2 −2
  6. include/uapi/linux/elfcore.h +4 −4
arch/mips/kernel/binfmt_elfn32.c+2−2
@@ -100,7 +100,7 @@ jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value) · 99 unmodified lines
100100 #undef TASK_SIZE
101101 #define TASK_SIZE TASK_SIZE32
102102
103−#undef ns_to_timeval
104−#define ns_to_timeval ns_to_old_timeval32
103+#undef ns_to_kernel_old_timeval
104+#define ns_to_kernel_old_timeval ns_to_old_timeval32
105105
106106 #include "../../../fs/binfmt_elf.c"
arch/mips/kernel/binfmt_elfo32.c+2−2
@@ -103,7 +103,7 @@ jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value) · 102 unmodified lines
103103 #undef TASK_SIZE
104104 #define TASK_SIZE TASK_SIZE32
105105
106−#undef ns_to_timeval
107−#define ns_to_timeval ns_to_old_timeval32
106+#undef ns_to_kernel_old_timeval
107+#define ns_to_kernel_old_timeval ns_to_old_timeval32
108108
109109 #include "../../../fs/binfmt_elf.c"
fs/binfmt_elf.c+6−6
@@ -1489,18 +1489,18 @@ static void fill_prstatus(struct elf_prstatus *prstatus, · 1488 unmodified lines
14891489 * group-wide total, not its individual thread total.
14901490 */
14911491 thread_group_cputime(p, &cputime);
1492− prstatus->pr_utime = ns_to_timeval(cputime.utime);
1493− prstatus->pr_stime = ns_to_timeval(cputime.stime);
1492+ prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime);
1493+ prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime);
14941494 } else {
14951495 u64 utime, stime;
14961496
14971497 task_cputime(p, &utime, &stime);
1498− prstatus->pr_utime = ns_to_timeval(utime);
1499− prstatus->pr_stime = ns_to_timeval(stime);
1498+ prstatus->pr_utime = ns_to_kernel_old_timeval(utime);
1499+ prstatus->pr_stime = ns_to_kernel_old_timeval(stime);
15001500 }
15011501
1502− prstatus->pr_cutime = ns_to_timeval(p->signal->cutime);
1503− prstatus->pr_cstime = ns_to_timeval(p->signal->cstime);
1502+ prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime);
1503+ prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime);
15041504 }
15051505
15061506 static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
fs/binfmt_elf_fdpic.c+6−6
@@ -1359,17 +1359,17 @@ static void fill_prstatus(struct elf_prstatus *prstatus, · 1358 unmodified lines
13591359 * group-wide total, not its individual thread total.
13601360 */
13611361 thread_group_cputime(p, &cputime);
1362− prstatus->pr_utime = ns_to_timeval(cputime.utime);
1363− prstatus->pr_stime = ns_to_timeval(cputime.stime);
1362+ prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime);
1363+ prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime);
13641364 } else {
13651365 u64 utime, stime;
13661366
13671367 task_cputime(p, &utime, &stime);
1368− prstatus->pr_utime = ns_to_timeval(utime);
1369− prstatus->pr_stime = ns_to_timeval(stime);
1368+ prstatus->pr_utime = ns_to_kernel_old_timeval(utime);
1369+ prstatus->pr_stime = ns_to_kernel_old_timeval(stime);
13701370 }
1371− prstatus->pr_cutime = ns_to_timeval(p->signal->cutime);
1372− prstatus->pr_cstime = ns_to_timeval(p->signal->cstime);
1371+ prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime);
1372+ prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime);
13731373
13741374 prstatus->pr_exec_fdpic_loadmap = p->mm->context.exec_fdpic_loadmap;
13751375 prstatus->pr_interp_fdpic_loadmap = p->mm->context.interp_fdpic_loadmap;
fs/compat_binfmt_elf.c+2−2
@@ -48,8 +48,8 @@ · 47 unmodified lines
4848 #define elf_prstatus compat_elf_prstatus
4949 #define elf_prpsinfo compat_elf_prpsinfo
5050
51−#undef ns_to_timeval
52−#define ns_to_timeval ns_to_old_timeval32
51+#undef ns_to_kernel_old_timeval
52+#define ns_to_kernel_old_timeval ns_to_old_timeval32
5353
5454 /*
5555 * To use this file, asm/elf.h must define compat_elf_check_arch.
include/uapi/linux/elfcore.h+4−4
@@ -53,10 +53,10 @@ struct elf_prstatus · 52 unmodified lines
5353 pid_t pr_ppid;
5454 pid_t pr_pgrp;
5555 pid_t pr_sid;
56− struct timeval pr_utime; /* User time */
57− struct timeval pr_stime; /* System time */
58− struct timeval pr_cutime; /* Cumulative user time */
59− struct timeval pr_cstime; /* Cumulative system time */
56+ struct __kernel_old_timeval pr_utime; /* User time */
57+ struct __kernel_old_timeval pr_stime; /* System time */
58+ struct __kernel_old_timeval pr_cutime; /* Cumulative user time */
59+ struct __kernel_old_timeval pr_cstime; /* Cumulative system time */
6060 #if 0
6161 long pr_instr; /* Current instruction */
6262 #endif