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.

kallsyms: cleanup code for appending the module buildid

Put the code for appending the optional "buildid" into a helper function,
It makes __sprint_symbol() better readable.

Also print a warning when the "modname" is set and the "buildid" isn't.
It might catch a situation when some lookup function in
kallsyms_lookup_buildid() does not handle the "buildid".

Use pr_*_once() to avoid an infinite recursion when the function is called
from printk(). The recursion is rather theoretical but better be on the
safe side.

Link: https://lkml.kernel.org/r/20251128135920.217303-5-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Cc: Aaron Tomlin <atomlin@atomlin.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: Daniel Gomez <da.gomez@samsung.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Luis Chamberalin <mcgrof@kernel.org>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Petr Pavlu <petr.pavlu@suse.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Petr Mladek and committed by
Andrew Morton
8e81dac4 acfdbb4a

+33 -9
+33 -9
kernel/kallsyms.c
··· 435 435 return lookup_module_symbol_name(addr, symname); 436 436 } 437 437 438 + #ifdef CONFIG_STACKTRACE_BUILD_ID 439 + 440 + static int append_buildid(char *buffer, const char *modname, 441 + const unsigned char *buildid) 442 + { 443 + if (!modname) 444 + return 0; 445 + 446 + if (!buildid) { 447 + pr_warn_once("Undefined buildid for the module %s\n", modname); 448 + return 0; 449 + } 450 + 451 + /* build ID should match length of sprintf */ 452 + #ifdef CONFIG_MODULES 453 + static_assert(sizeof(typeof_member(struct module, build_id)) == 20); 454 + #endif 455 + 456 + return sprintf(buffer, " %20phN", buildid); 457 + } 458 + 459 + #else /* CONFIG_STACKTRACE_BUILD_ID */ 460 + 461 + static int append_buildid(char *buffer, const char *modname, 462 + const unsigned char *buildid) 463 + { 464 + return 0; 465 + } 466 + 467 + #endif /* CONFIG_STACKTRACE_BUILD_ID */ 468 + 438 469 /* Look up a kernel symbol and return it in a text buffer. */ 439 470 static int __sprint_symbol(char *buffer, unsigned long address, 440 471 int symbol_offset, int add_offset, int add_buildid) ··· 488 457 489 458 if (modname) { 490 459 len += sprintf(buffer + len, " [%s", modname); 491 - #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) 492 - if (add_buildid && buildid) { 493 - /* build ID should match length of sprintf */ 494 - #if IS_ENABLED(CONFIG_MODULES) 495 - static_assert(sizeof(typeof_member(struct module, build_id)) == 20); 496 - #endif 497 - len += sprintf(buffer + len, " %20phN", buildid); 498 - } 499 - #endif 460 + if (add_buildid) 461 + len += append_buildid(buffer + len, modname, buildid); 500 462 len += sprintf(buffer + len, "]"); 501 463 } 502 464