Skip to content
/ linux Public

Commit af0f0d3

Browse files
pmladekSasha Levin
authored andcommitted
kallsyms/ftrace: set module buildid in ftrace_mod_address_lookup()
[ Upstream commit e8a1e7e ] __sprint_symbol() might access an invalid pointer when kallsyms_lookup_buildid() returns a symbol found by ftrace_mod_address_lookup(). The ftrace lookup function must set both @modname and @modbuildid the same way as module_address_lookup(). Link: https://lkml.kernel.org/r/20251128135920.217303-7-pmladek@suse.com Fixes: 9294523 ("module: add printk formats to add module build ID to stacktraces") Signed-off-by: Petr Mladek <pmladek@suse.com> Reviewed-by: Aaron Tomlin <atomlin@atomlin.com> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org> 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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ecb0af9 commit af0f0d3

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

include/linux/ftrace.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ struct ftrace_direct_func;
8989
defined(CONFIG_DYNAMIC_FTRACE)
9090
const char *
9191
ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
92-
unsigned long *off, char **modname, char *sym);
92+
unsigned long *off, char **modname,
93+
const unsigned char **modbuildid, char *sym);
9394
#else
9495
static inline const char *
9596
ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
96-
unsigned long *off, char **modname, char *sym)
97+
unsigned long *off, char **modname,
98+
const unsigned char **modbuildid, char *sym)
9799
{
98100
return NULL;
99101
}

kernel/kallsyms.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ static const char *kallsyms_lookup_buildid(unsigned long addr,
431431
offset, modname, namebuf);
432432

433433
if (!ret)
434-
ret = ftrace_mod_address_lookup(addr, symbolsize,
435-
offset, modname, namebuf);
434+
ret = ftrace_mod_address_lookup(addr, symbolsize, offset,
435+
modname, modbuildid, namebuf);
436436

437437
found:
438438
cleanup_symbol_name(namebuf);

kernel/trace/ftrace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7046,7 +7046,8 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod_map,
70467046

70477047
const char *
70487048
ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
7049-
unsigned long *off, char **modname, char *sym)
7049+
unsigned long *off, char **modname,
7050+
const unsigned char **modbuildid, char *sym)
70507051
{
70517052
struct ftrace_mod_map *mod_map;
70527053
const char *ret = NULL;
@@ -7058,6 +7059,8 @@ ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
70587059
if (ret) {
70597060
if (modname)
70607061
*modname = mod_map->mod->name;
7062+
if (modbuildid)
7063+
*modbuildid = module_buildid(mod_map->mod);
70617064
break;
70627065
}
70637066
}

0 commit comments

Comments
 (0)