diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-17 11:16:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-17 11:16:36 -0400 |
commit | 0666f560b71b899cd11a7caf39fd45129e9030fd (patch) | |
tree | 24c537b475c6237e99af316d34605a9ad52f3a12 /tools | |
parent | e77d3b0c4a6a973872652601aae35d4ab1785fb4 (diff) | |
parent | fd7d56270b526ca3ed0c224362e3c64a0f86687a (diff) |
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()
Diffstat (limited to 'tools')
-rw-r--r-- | tools/objtool/elf.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 6e9f980a7d26..24460155c82c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c | |||
@@ -175,19 +175,20 @@ static int read_sections(struct elf *elf) | |||
175 | return -1; | 175 | return -1; |
176 | } | 176 | } |
177 | 177 | ||
178 | sec->data = elf_getdata(s, NULL); | 178 | if (sec->sh.sh_size != 0) { |
179 | if (!sec->data) { | 179 | sec->data = elf_getdata(s, NULL); |
180 | WARN_ELF("elf_getdata"); | 180 | if (!sec->data) { |
181 | return -1; | 181 | WARN_ELF("elf_getdata"); |
182 | } | 182 | return -1; |
183 | 183 | } | |
184 | if (sec->data->d_off != 0 || | 184 | if (sec->data->d_off != 0 || |
185 | sec->data->d_size != sec->sh.sh_size) { | 185 | sec->data->d_size != sec->sh.sh_size) { |
186 | WARN("unexpected data attributes for %s", sec->name); | 186 | WARN("unexpected data attributes for %s", |
187 | return -1; | 187 | sec->name); |
188 | return -1; | ||
189 | } | ||
188 | } | 190 | } |
189 | 191 | sec->len = sec->sh.sh_size; | |
190 | sec->len = sec->data->d_size; | ||
191 | } | 192 | } |
192 | 193 | ||
193 | /* sanity check, one more call to elf_nextscn() should return NULL */ | 194 | /* 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) | |||
508 | strcat(relaname, base->name); | 509 | strcat(relaname, base->name); |
509 | 510 | ||
510 | sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); | 511 | sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); |
512 | free(relaname); | ||
511 | if (!sec) | 513 | if (!sec) |
512 | return NULL; | 514 | return NULL; |
513 | 515 | ||
@@ -561,6 +563,7 @@ int elf_write(struct elf *elf) | |||
561 | struct section *sec; | 563 | struct section *sec; |
562 | Elf_Scn *s; | 564 | Elf_Scn *s; |
563 | 565 | ||
566 | /* Update section headers for changed sections: */ | ||
564 | list_for_each_entry(sec, &elf->sections, list) { | 567 | list_for_each_entry(sec, &elf->sections, list) { |
565 | if (sec->changed) { | 568 | if (sec->changed) { |
566 | s = elf_getscn(elf->elf, sec->idx); | 569 | s = elf_getscn(elf->elf, sec->idx); |
@@ -568,13 +571,17 @@ int elf_write(struct elf *elf) | |||
568 | WARN_ELF("elf_getscn"); | 571 | WARN_ELF("elf_getscn"); |
569 | return -1; | 572 | return -1; |
570 | } | 573 | } |
571 | if (!gelf_update_shdr (s, &sec->sh)) { | 574 | if (!gelf_update_shdr(s, &sec->sh)) { |
572 | WARN_ELF("gelf_update_shdr"); | 575 | WARN_ELF("gelf_update_shdr"); |
573 | return -1; | 576 | return -1; |
574 | } | 577 | } |
575 | } | 578 | } |
576 | } | 579 | } |
577 | 580 | ||
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. */ | ||
578 | if (elf_update(elf->elf, ELF_C_WRITE) < 0) { | 585 | if (elf_update(elf->elf, ELF_C_WRITE) < 0) { |
579 | WARN_ELF("elf_update"); | 586 | WARN_ELF("elf_update"); |
580 | return -1; | 587 | return -1; |