* [PATCH v3] kallsyms: Always initialize modbuildid
@ 2025-12-10 17:03 Maurice Hieronymus
2025-12-17 22:27 ` Steven Rostedt
2025-12-17 22:30 ` Steven Rostedt
0 siblings, 2 replies; 3+ messages in thread
From: Maurice Hieronymus @ 2025-12-10 17:03 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Steven Rostedt, Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers
Cc: georges.aureau, Maurice Hieronymus, bpf, linux-kernel,
linux-trace-kernel
modbuildid is never set when kallsyms_lookup_buildid is returning via
successful bpf_address_lookup or ftrace_mod_address_lookup.
This leads to an uninitialized pointer dereference on x86 when
CONFIG_STACKTRACE_BUILD_ID=y inside __sprint_symbol.
Prevent this by always initializing modbuildid.
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220717
Signed-off-by: Maurice Hieronymus <mhi@mailbox.org>
---
Changes to v2:
- Check if CONFIG_STACKTRACE_BUILD_ID is enabled to prevent build fail
Changes to v1:
- Set modbuildid in ftrace_func_address_lookup
include/linux/filter.h | 6 ++++--
include/linux/ftrace.h | 4 ++--
kernel/kallsyms.c | 4 ++--
kernel/trace/ftrace.c | 8 +++++++-
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index fd54fed8f95f..eb1d1c876503 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -1384,12 +1384,14 @@ struct bpf_prog *bpf_prog_ksym_find(unsigned long addr);
static inline int
bpf_address_lookup(unsigned long addr, unsigned long *size,
- unsigned long *off, char **modname, char *sym)
+ unsigned long *off, char **modname, const unsigned char **modbuildid, char *sym)
{
int ret = __bpf_address_lookup(addr, size, off, sym);
if (ret && modname)
*modname = NULL;
+ if (ret && modbuildid)
+ *modbuildid = NULL;
return ret;
}
@@ -1455,7 +1457,7 @@ static inline struct bpf_prog *bpf_prog_ksym_find(unsigned long addr)
static inline int
bpf_address_lookup(unsigned long addr, unsigned long *size,
- unsigned long *off, char **modname, char *sym)
+ unsigned long *off, char **modname, const unsigned char **modbuildid, char *sym)
{
return 0;
}
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 770f0dc993cc..ed673fa2536b 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -87,11 +87,11 @@ struct ftrace_hash;
defined(CONFIG_DYNAMIC_FTRACE)
int
ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
- unsigned long *off, char **modname, char *sym);
+ unsigned long *off, char **modname, const unsigned char **modbuildid, char *sym);
#else
static inline int
ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
- unsigned long *off, char **modname, char *sym)
+ unsigned long *off, char **modname, const unsigned char **modbuildid, char *sym)
{
return 0;
}
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 049e296f586c..b1516d3fa9c5 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -378,11 +378,11 @@ static int kallsyms_lookup_buildid(unsigned long addr,
modname, modbuildid, namebuf);
if (!ret)
ret = bpf_address_lookup(addr, symbolsize,
- offset, modname, namebuf);
+ offset, modname, modbuildid, namebuf);
if (!ret)
ret = ftrace_mod_address_lookup(addr, symbolsize,
- offset, modname, namebuf);
+ offset, modname, modbuildid, namebuf);
return ret;
}
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 3ec2033c0774..4e4aef987747 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -7749,7 +7749,7 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod_map,
int
ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
- unsigned long *off, char **modname, char *sym)
+ unsigned long *off, char **modname, const unsigned char **modbuildid, char *sym)
{
struct ftrace_mod_map *mod_map;
int ret = 0;
@@ -7761,6 +7761,12 @@ ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
if (ret) {
if (modname)
*modname = mod_map->mod->name;
+ if (modbuildid)
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+ *modbuildid = mod_map->mod->build_id;
+#else
+ *modbuildid = NULL;
+#endif
break;
}
}
base-commit: 0048fbb4011ec55c32d3148b2cda56433f273375
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] kallsyms: Always initialize modbuildid
2025-12-10 17:03 [PATCH v3] kallsyms: Always initialize modbuildid Maurice Hieronymus
@ 2025-12-17 22:27 ` Steven Rostedt
2025-12-17 22:30 ` Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2025-12-17 22:27 UTC (permalink / raw)
To: Maurice Hieronymus
Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, georges.aureau,
bpf, linux-kernel, linux-trace-kernel
On Wed, 10 Dec 2025 18:03:45 +0100
Maurice Hieronymus <mhi@mailbox.org> wrote:
> @@ -7761,6 +7761,12 @@ ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
> if (ret) {
> if (modname)
> *modname = mod_map->mod->name;
> + if (modbuildid)
> +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
IS_ENABLED() is for use within C code. This should simply be:
#ifdef CONFIG_STACKTRACE_BUILD_ID
-- Steve
> + *modbuildid = mod_map->mod->build_id;
> +#else
> + *modbuildid = NULL;
> +#endif
> break;
> }
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] kallsyms: Always initialize modbuildid
2025-12-10 17:03 [PATCH v3] kallsyms: Always initialize modbuildid Maurice Hieronymus
2025-12-17 22:27 ` Steven Rostedt
@ 2025-12-17 22:30 ` Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2025-12-17 22:30 UTC (permalink / raw)
To: Maurice Hieronymus
Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, georges.aureau,
bpf, linux-kernel, linux-trace-kernel
On Wed, 10 Dec 2025 18:03:45 +0100
Maurice Hieronymus <mhi@mailbox.org> wrote:
> include/linux/filter.h | 6 ++++--
> include/linux/ftrace.h | 4 ++--
> kernel/kallsyms.c | 4 ++--
> kernel/trace/ftrace.c | 8 +++++++-
> 4 files changed, 15 insertions(+), 7 deletions(-)
Also split this up into two patches. Then I can take the one for ftrace and
the networking folks can take the bpf update.
-- Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-17 22:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 17:03 [PATCH v3] kallsyms: Always initialize modbuildid Maurice Hieronymus
2025-12-17 22:27 ` Steven Rostedt
2025-12-17 22:30 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox