Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

objtool: Remove max symbol name length limitation

If one of the symbols processed by read_symbols() happens to have a
.cold variant with a name longer than objtool's MAX_NAME_LEN limit, the
build fails.

Avoid this problem by just using strndup() to copy the parent function's
name, rather than strncpy()ing it onto the stack.

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Link: https://lore.kernel.org/r/41e94cfea1d9131b758dd637fecdeacd459d4584.1696355111.git.aplattner@nvidia.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

authored by

Aaron Plattner and committed by
Josh Poimboeuf
f404a58d e959c279

+6 -8
+6 -8
tools/objtool/elf.c
··· 22 22 #include <objtool/elf.h> 23 23 #include <objtool/warn.h> 24 24 25 - #define MAX_NAME_LEN 128 26 - 27 25 static inline u32 str_hash(const char *str) 28 26 { 29 27 return jhash(str, strlen(str), 0); ··· 513 515 /* Create parent/child links for any cold subfunctions */ 514 516 list_for_each_entry(sec, &elf->sections, list) { 515 517 sec_for_each_sym(sec, sym) { 516 - char pname[MAX_NAME_LEN + 1]; 518 + char *pname; 517 519 size_t pnamelen; 518 520 if (sym->type != STT_FUNC) 519 521 continue; ··· 529 531 continue; 530 532 531 533 pnamelen = coldstr - sym->name; 532 - if (pnamelen > MAX_NAME_LEN) { 533 - WARN("%s(): parent function name exceeds maximum length of %d characters", 534 - sym->name, MAX_NAME_LEN); 534 + pname = strndup(sym->name, pnamelen); 535 + if (!pname) { 536 + WARN("%s(): failed to allocate memory", 537 + sym->name); 535 538 return -1; 536 539 } 537 540 538 - strncpy(pname, sym->name, pnamelen); 539 - pname[pnamelen] = '\0'; 540 541 pfunc = find_symbol_by_name(elf, pname); 542 + free(pname); 541 543 542 544 if (!pfunc) { 543 545 WARN("%s(): can't find parent function",