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

Configure Feed

Select the types of activity you want to include in your feed.

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>

+9 -6
+9 -6
tools/objtool/klp-diff.c
··· 1352 1352 { 1353 1353 bool static_branch = !strcmp(sym->sec->name, "__jump_table"); 1354 1354 bool static_call = !strcmp(sym->sec->name, ".static_call_sites"); 1355 - struct symbol *code_sym = NULL; 1355 + const char *code_sym = NULL; 1356 1356 unsigned long code_offset = 0; 1357 1357 struct reloc *reloc; 1358 1358 int ret = 0; ··· 1372 1372 1373 1373 /* Save code location which can be printed below */ 1374 1374 if (reloc->sym->type == STT_FUNC && !code_sym) { 1375 - code_sym = reloc->sym; 1375 + code_sym = reloc->sym->name; 1376 1376 code_offset = reloc_addend(reloc); 1377 1377 } 1378 1378 ··· 1395 1395 if (!strcmp(sym_modname, "vmlinux")) 1396 1396 continue; 1397 1397 1398 + if (!code_sym) 1399 + code_sym = "<unknown>"; 1400 + 1398 1401 if (static_branch) { 1399 1402 if (strstarts(reloc->sym->name, "__tracepoint_")) { 1400 1403 WARN("%s: disabling unsupported tracepoint %s", 1401 - code_sym->name, reloc->sym->name + 13); 1404 + code_sym, reloc->sym->name + 13); 1402 1405 ret = 1; 1403 1406 continue; 1404 1407 } 1405 1408 1406 1409 if (strstr(reloc->sym->name, "__UNIQUE_ID_ddebug_")) { 1407 1410 WARN("%s: disabling unsupported pr_debug()", 1408 - code_sym->name); 1411 + code_sym); 1409 1412 ret = 1; 1410 1413 continue; 1411 1414 } 1412 1415 1413 1416 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); 1415 1418 return -1; 1416 1419 } 1417 1420 ··· 1425 1422 } 1426 1423 1427 1424 ERROR("%s()+0x%lx: unsupported static call key %s. Use KLP_STATIC_CALL() instead", 1428 - code_sym->name, code_offset, reloc->sym->name); 1425 + code_sym, code_offset, reloc->sym->name); 1429 1426 return -1; 1430 1427 } 1431 1428