Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull misc fixes from Thomas Gleixner:

- A fix for a user space regression in /proc/$PID/stat

- A couple of objtool fixes:
~ Plug a memory leak
~ Avoid accessing empty sections which upsets certain binutil
versions
~ Prevent corrupting the obj file when section sizes did not change

* 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
fs/proc: Report eip/esp in /prod/PID/stat for coredumping
objtool: Fix object file corruption
objtool: Do not retrieve data from empty sections
objtool: Fix memory leak in elf_create_rela_section()

Changed files
+29 -13
fs
proc
tools
objtool
+9
fs/proc/array.c
··· 62 62 #include <linux/mman.h> 63 63 #include <linux/sched/mm.h> 64 64 #include <linux/sched/numa_balancing.h> 65 + #include <linux/sched/task_stack.h> 65 66 #include <linux/sched/task.h> 66 67 #include <linux/sched/cputime.h> 67 68 #include <linux/proc_fs.h> ··· 422 421 * esp and eip are intentionally zeroed out. There is no 423 422 * non-racy way to read them without freezing the task. 424 423 * Programs that need reliable values can use ptrace(2). 424 + * 425 + * The only exception is if the task is core dumping because 426 + * a program is not able to use ptrace(2) in that case. It is 427 + * safe because the task has stopped executing permanently. 425 428 */ 429 + if (permitted && (task->flags & PF_DUMPCORE)) { 430 + eip = KSTK_EIP(task); 431 + esp = KSTK_ESP(task); 432 + } 426 433 } 427 434 428 435 get_task_comm(tcomm, task);
+20 -13
tools/objtool/elf.c
··· 175 175 return -1; 176 176 } 177 177 178 - sec->data = elf_getdata(s, NULL); 179 - if (!sec->data) { 180 - WARN_ELF("elf_getdata"); 181 - return -1; 178 + if (sec->sh.sh_size != 0) { 179 + sec->data = elf_getdata(s, NULL); 180 + if (!sec->data) { 181 + WARN_ELF("elf_getdata"); 182 + return -1; 183 + } 184 + if (sec->data->d_off != 0 || 185 + sec->data->d_size != sec->sh.sh_size) { 186 + WARN("unexpected data attributes for %s", 187 + sec->name); 188 + return -1; 189 + } 182 190 } 183 - 184 - if (sec->data->d_off != 0 || 185 - sec->data->d_size != sec->sh.sh_size) { 186 - WARN("unexpected data attributes for %s", sec->name); 187 - return -1; 188 - } 189 - 190 - sec->len = sec->data->d_size; 191 + sec->len = sec->sh.sh_size; 191 192 } 192 193 193 194 /* sanity check, one more call to elf_nextscn() should return NULL */ ··· 509 508 strcat(relaname, base->name); 510 509 511 510 sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); 511 + free(relaname); 512 512 if (!sec) 513 513 return NULL; 514 514 ··· 563 561 struct section *sec; 564 562 Elf_Scn *s; 565 563 564 + /* Update section headers for changed sections: */ 566 565 list_for_each_entry(sec, &elf->sections, list) { 567 566 if (sec->changed) { 568 567 s = elf_getscn(elf->elf, sec->idx); ··· 571 568 WARN_ELF("elf_getscn"); 572 569 return -1; 573 570 } 574 - if (!gelf_update_shdr (s, &sec->sh)) { 571 + if (!gelf_update_shdr(s, &sec->sh)) { 575 572 WARN_ELF("gelf_update_shdr"); 576 573 return -1; 577 574 } 578 575 } 579 576 } 580 577 578 + /* Make sure the new section header entries get updated properly. */ 579 + elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY); 580 + 581 + /* Write all changes to the file. */ 581 582 if (elf_update(elf->elf, ELF_C_WRITE) < 0) { 582 583 WARN_ELF("elf_update"); 583 584 return -1;