Commit 575d7d0d authored by Linus Torvalds's avatar Linus Torvalds

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

Pull objtool fixes from Ingo Molnar:
 "Two fixes for boundary conditions"

* 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  objtool: Fix segfault in .cold detection with -ffunction-sections
  objtool: Fix double-free in .cold detection error path
parents 5f1ca5c6 22566c16
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "elf.h" #include "elf.h"
#include "warn.h" #include "warn.h"
#define MAX_NAME_LEN 128
struct section *find_section_by_name(struct elf *elf, const char *name) struct section *find_section_by_name(struct elf *elf, const char *name)
{ {
struct section *sec; struct section *sec;
...@@ -298,6 +300,8 @@ static int read_symbols(struct elf *elf) ...@@ -298,6 +300,8 @@ static int read_symbols(struct elf *elf)
/* Create parent/child links for any cold subfunctions */ /* Create parent/child links for any cold subfunctions */
list_for_each_entry(sec, &elf->sections, list) { list_for_each_entry(sec, &elf->sections, list) {
list_for_each_entry(sym, &sec->symbol_list, list) { list_for_each_entry(sym, &sec->symbol_list, list) {
char pname[MAX_NAME_LEN + 1];
size_t pnamelen;
if (sym->type != STT_FUNC) if (sym->type != STT_FUNC)
continue; continue;
sym->pfunc = sym->cfunc = sym; sym->pfunc = sym->cfunc = sym;
...@@ -305,14 +309,21 @@ static int read_symbols(struct elf *elf) ...@@ -305,14 +309,21 @@ static int read_symbols(struct elf *elf)
if (!coldstr) if (!coldstr)
continue; continue;
coldstr[0] = '\0'; pnamelen = coldstr - sym->name;
pfunc = find_symbol_by_name(elf, sym->name); if (pnamelen > MAX_NAME_LEN) {
coldstr[0] = '.'; WARN("%s(): parent function name exceeds maximum length of %d characters",
sym->name, MAX_NAME_LEN);
return -1;
}
strncpy(pname, sym->name, pnamelen);
pname[pnamelen] = '\0';
pfunc = find_symbol_by_name(elf, pname);
if (!pfunc) { if (!pfunc) {
WARN("%s(): can't find parent function", WARN("%s(): can't find parent function",
sym->name); sym->name);
goto err; return -1;
} }
sym->pfunc = pfunc; sym->pfunc = pfunc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment