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
100#undef TASK_SIZE100#undef TASK_SIZE
101#define TASK_SIZE TASK_SIZE32101#define TASK_SIZE TASK_SIZE32
102 102
103#undef ns_to_timeval103#undef ns_to_kernel_old_timeval
104#define ns_to_timeval ns_to_old_timeval32104#define ns_to_kernel_old_timeval ns_to_old_timeval32
105 105
106#include "../../../fs/binfmt_elf.c"106#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
103#undef TASK_SIZE103#undef TASK_SIZE
104#define TASK_SIZE TASK_SIZE32104#define TASK_SIZE TASK_SIZE32
105 105
106#undef ns_to_timeval106#undef ns_to_kernel_old_timeval
107#define ns_to_timeval ns_to_old_timeval32107#define ns_to_kernel_old_timeval ns_to_old_timeval32
108 108
109#include "../../../fs/binfmt_elf.c"109#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
1489 * group-wide total, not its individual thread total.1489 * group-wide total, not its individual thread total.
1490 */1490 */
1491 thread_group_cputime(p, &cputime);1491 thread_group_cputime(p, &cputime);
1492 prstatus->pr_utime = ns_to_timeval(cputime.utime);1492 prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime);
1493 prstatus->pr_stime = ns_to_timeval(cputime.stime);1493 prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime);
1494 } else {1494 } else {
1495 u64 utime, stime;1495 u64 utime, stime;
1496 1496
1497 task_cputime(p, &utime, &stime);1497 task_cputime(p, &utime, &stime);
1498 prstatus->pr_utime = ns_to_timeval(utime);1498 prstatus->pr_utime = ns_to_kernel_old_timeval(utime);
1499 prstatus->pr_stime = ns_to_timeval(stime);1499 prstatus->pr_stime = ns_to_kernel_old_timeval(stime);
1500 }1500 }
1501 1501
1502 prstatus->pr_cutime = ns_to_timeval(p->signal->cutime);1502 prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime);
1503 prstatus->pr_cstime = ns_to_timeval(p->signal->cstime);1503 prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime);
1504}1504}
1505 1505
1506static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,1506static 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
1359 * group-wide total, not its individual thread total.1359 * group-wide total, not its individual thread total.
1360 */1360 */
1361 thread_group_cputime(p, &cputime);1361 thread_group_cputime(p, &cputime);
1362 prstatus->pr_utime = ns_to_timeval(cputime.utime);1362 prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime);
1363 prstatus->pr_stime = ns_to_timeval(cputime.stime);1363 prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime);
1364 } else {1364 } else {
1365 u64 utime, stime;1365 u64 utime, stime;
1366 1366
1367 task_cputime(p, &utime, &stime);1367 task_cputime(p, &utime, &stime);
1368 prstatus->pr_utime = ns_to_timeval(utime);1368 prstatus->pr_utime = ns_to_kernel_old_timeval(utime);
1369 prstatus->pr_stime = ns_to_timeval(stime);1369 prstatus->pr_stime = ns_to_kernel_old_timeval(stime);
1370 }1370 }
1371 prstatus->pr_cutime = ns_to_timeval(p->signal->cutime);1371 prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime);
1372 prstatus->pr_cstime = ns_to_timeval(p->signal->cstime);1372 prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime);
1373 1373
1374 prstatus->pr_exec_fdpic_loadmap = p->mm->context.exec_fdpic_loadmap;1374 prstatus->pr_exec_fdpic_loadmap = p->mm->context.exec_fdpic_loadmap;
1375 prstatus->pr_interp_fdpic_loadmap = p->mm->context.interp_fdpic_loadmap;1375 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
48#define elf_prstatus compat_elf_prstatus48#define elf_prstatus compat_elf_prstatus
49#define elf_prpsinfo compat_elf_prpsinfo49#define elf_prpsinfo compat_elf_prpsinfo
50 50
51#undef ns_to_timeval51#undef ns_to_kernel_old_timeval
52#define ns_to_timeval ns_to_old_timeval3252#define ns_to_kernel_old_timeval ns_to_old_timeval32
53 53
54/*54/*
55 * To use this file, asm/elf.h must define compat_elf_check_arch.55 * 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
53 pid_t pr_ppid;53 pid_t pr_ppid;
54 pid_t pr_pgrp;54 pid_t pr_pgrp;
55 pid_t pr_sid;55 pid_t pr_sid;
56 struct timeval pr_utime; /* User time */56 struct __kernel_old_timeval pr_utime; /* User time */
57 struct timeval pr_stime; /* System time */57 struct __kernel_old_timeval pr_stime; /* System time */
58 struct timeval pr_cutime; /* Cumulative user time */58 struct __kernel_old_timeval pr_cutime; /* Cumulative user time */
59 struct timeval pr_cstime; /* Cumulative system time */59 struct __kernel_old_timeval pr_cstime; /* Cumulative system time */
60#if 060#if 0
61 long pr_instr; /* Current instruction */61 long pr_instr; /* Current instruction */
62#endif62#endif