Skip to content

Commit 0666f56

Browse files
committed
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()
2 parents e77d3b0 + fd7d562 commit 0666f56

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

fs/proc/array.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/mman.h>
6363
#include <linux/sched/mm.h>
6464
#include <linux/sched/numa_balancing.h>
65+
#include <linux/sched/task_stack.h>
6566
#include <linux/sched/task.h>
6667
#include <linux/sched/cputime.h>
6768
#include <linux/proc_fs.h>
@@ -421,7 +422,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
421422
* esp and eip are intentionally zeroed out. There is no
422423
* non-racy way to read them without freezing the task.
423424
* Programs that need reliable values can use ptrace(2).
425+
*
426+
* The only exception is if the task is core dumping because
427+
* a program is not able to use ptrace(2) in that case. It is
428+
* safe because the task has stopped executing permanently.
424429
*/
430+
if (permitted && (task->flags & PF_DUMPCORE)) {
431+
eip = KSTK_EIP(task);
432+
esp = KSTK_ESP(task);
433+
}
425434
}
426435

427436
get_task_comm(tcomm, task);

tools/objtool/elf.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,20 @@ static int read_sections(struct elf *elf)
175175
return -1;
176176
}
177177

178-
sec->data = elf_getdata(s, NULL);
179-
if (!sec->data) {
180-
WARN_ELF("elf_getdata");
181-
return -1;
182-
}
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;
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+
}
188190
}
189-
190-
sec->len = sec->data->d_size;
191+
sec->len = sec->sh.sh_size;
191192
}
192193

193194
/* sanity check, one more call to elf_nextscn() should return NULL */
@@ -508,6 +509,7 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *base)
508509
strcat(relaname, base->name);
509510

510511
sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0);
512+
free(relaname);
511513
if (!sec)
512514
return NULL;
513515

@@ -561,20 +563,25 @@ int elf_write(struct elf *elf)
561563
struct section *sec;
562564
Elf_Scn *s;
563565

566+
/* Update section headers for changed sections: */
564567
list_for_each_entry(sec, &elf->sections, list) {
565568
if (sec->changed) {
566569
s = elf_getscn(elf->elf, sec->idx);
567570
if (!s) {
568571
WARN_ELF("elf_getscn");
569572
return -1;
570573
}
571-
if (!gelf_update_shdr (s, &sec->sh)) {
574+
if (!gelf_update_shdr(s, &sec->sh)) {
572575
WARN_ELF("gelf_update_shdr");
573576
return -1;
574577
}
575578
}
576579
}
577580

581+
/* Make sure the new section header entries get updated properly. */
582+
elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY);
583+
584+
/* Write all changes to the file. */
578585
if (elf_update(elf->elf, ELF_C_WRITE) < 0) {
579586
WARN_ELF("elf_update");
580587
return -1;

0 commit comments

Comments
 (0)