Skip to content

Commit 11c2adc

Browse files
committed
objtool/klp: Avoid NULL pointer dereference when printing code symbol name
Fix a hypothetical NULL pointer defereference of the 'code_sym' variable. In theory this should never happen. Reviewed-and-tested-by: Song Liu <song@kernel.org> Link: https://patch.msgid.link/64116517bc93851a98fe366ea0a4d807f4c70aab.1770759954.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
1 parent e476bb2 commit 11c2adc

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

tools/objtool/klp-diff.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym
13521352
{
13531353
bool static_branch = !strcmp(sym->sec->name, "__jump_table");
13541354
bool static_call = !strcmp(sym->sec->name, ".static_call_sites");
1355-
struct symbol *code_sym = NULL;
1355+
const char *code_sym = NULL;
13561356
unsigned long code_offset = 0;
13571357
struct reloc *reloc;
13581358
int ret = 0;
@@ -1372,7 +1372,7 @@ static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym
13721372

13731373
/* Save code location which can be printed below */
13741374
if (reloc->sym->type == STT_FUNC && !code_sym) {
1375-
code_sym = reloc->sym;
1375+
code_sym = reloc->sym->name;
13761376
code_offset = reloc_addend(reloc);
13771377
}
13781378

@@ -1395,23 +1395,26 @@ static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym
13951395
if (!strcmp(sym_modname, "vmlinux"))
13961396
continue;
13971397

1398+
if (!code_sym)
1399+
code_sym = "<unknown>";
1400+
13981401
if (static_branch) {
13991402
if (strstarts(reloc->sym->name, "__tracepoint_")) {
14001403
WARN("%s: disabling unsupported tracepoint %s",
1401-
code_sym->name, reloc->sym->name + 13);
1404+
code_sym, reloc->sym->name + 13);
14021405
ret = 1;
14031406
continue;
14041407
}
14051408

14061409
if (strstr(reloc->sym->name, "__UNIQUE_ID_ddebug_")) {
14071410
WARN("%s: disabling unsupported pr_debug()",
1408-
code_sym->name);
1411+
code_sym);
14091412
ret = 1;
14101413
continue;
14111414
}
14121415

14131416
ERROR("%s+0x%lx: unsupported static branch key %s. Use static_key_enabled() instead",
1414-
code_sym->name, code_offset, reloc->sym->name);
1417+
code_sym, code_offset, reloc->sym->name);
14151418
return -1;
14161419
}
14171420

@@ -1422,7 +1425,7 @@ static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym
14221425
}
14231426

14241427
ERROR("%s()+0x%lx: unsupported static call key %s. Use KLP_STATIC_CALL() instead",
1425-
code_sym->name, code_offset, reloc->sym->name);
1428+
code_sym, code_offset, reloc->sym->name);
14261429
return -1;
14271430
}
14281431

0 commit comments

Comments
 (0)