Skip to contentSkip to conversation

kallsyms: Always initialize modbuildid

PATCH In review Maurice Hieronymus 3 participants 6 messages Dec 20, 2025 – Jan 7

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover kallsyms: Always initialize modbuildid

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.

Changes to v3:
- Split the changes into separate ftrace and bpf patches
- Replace IS_ENABLED() with plain #ifdef

Maurice Hieronymus (2):
kallsyms: Always initialize modbuildid on ftrace address
kallsyms: Always initialize modbuildid on bpf address

 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(-)

base-commit: dd9b004b7ff3289fb7bae35130c0a5c0537266af

Signature · 1 line
2.50.1
#1 lore raw

PATCH v4 1/2 kallsyms: Always initialize modbuildid on ftrace address

modbuildid is never set when kallsyms_lookup_buildid is returning via successful 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.

---
 include/linux/ftrace.h | 4 ++--
 kernel/kallsyms.c      | 2 +-
 kernel/trace/ftrace.c  | 8 +++++++-
 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/ftrace.h +2 -2
index 770f0dc993cc..ed673fa2536b 100644
@@ -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;
 }
kernel/kallsyms.c +1 -1
index 049e296f586c..5ca69eafda7a 100644
@@ -382,7 +382,7 @@ static int kallsyms_lookup_buildid(unsigned long addr,
 
 	if (!ret)
 		ret = ftrace_mod_address_lookup(addr, symbolsize,
-						offset, modname, namebuf);
+						offset, modname, modbuildid, namebuf);
 
 	return ret;
 }
kernel/trace/ftrace.c +7 -1
index ef2d5dca6f70..6eba92a52261 100644
@@ -7752,7 +7752,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;
@@ -7764,6 +7764,12 @@ ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
 		if (ret) {
 			if (modname)
 				*modname = mod_map->mod->name;
+			if (modbuildid)
+#ifdef CONFIG_STACKTRACE_BUILD_ID
+				*modbuildid = mod_map->mod->build_id;
+#else
+				*modbuildid = NULL;
+#endif
 			break;
 		}
 	}
Signature · 1 line
2.50.1
maintainer
#2 lore raw

Re: [PATCH v4 1/2] kallsyms: Always initialize modbuildid on ftrace address

Quoted 6 lines · On Sat, 20 Dec 2025 19:18:37 +0100 Maurice Hieronymus <[email protected]> wrote:

modbuildid is never set when kallsyms_lookup_buildid is returning via successful ftrace_mod_address_lookup.

This leads to an uninitialized pointer dereference on x86 when CONFIG_STACKTRACE_BUILD_ID=y inside __sprint_symbol.

Nothing should be getting a buildid from the ftrace kallsyms lookup.

This code is used to find the names of init functions of modules after those init functions have been freed. Nothing but ftrace should be looking for these addresses, and ftrace doesn't care about buildids.

-- Steve

#3 lore raw

PATCH v4 2/2 kallsyms: Always initialize modbuildid on bpf address

In reply to Maurice Hieronymus

modbuildid is never set when kallsyms_lookup_buildid is returning via successful bpf_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.

---
 include/linux/filter.h | 6 ++++--
 kernel/kallsyms.c      | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
include/linux/filter.h +4 -2
index fd54fed8f95f..eb1d1c876503 100644
@@ -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;
 }
kernel/kallsyms.c +1 -1
index 5ca69eafda7a..b1516d3fa9c5 100644
@@ -378,7 +378,7 @@ 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,
Signature · 1 line
2.50.1
#4 lore raw

Re: [PATCH v4 2/2] kallsyms: Always initialize modbuildid on bpf address

Quoted 37 lines · Maurice Hieronymus

modbuildid is never set when kallsyms_lookup_buildid is returning via successful bpf_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.

---
 include/linux/filter.h | 6 ++++--
 kernel/kallsyms.c      | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
include/linux/filter.h +3 -1
index fd54fed8f95f..eb1d1c876503 100644
@@ -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;
 }
 

include/linux/filter.h static inline struct bpf_prog *bpf_prog_ksym_find(unsigned long addr) · line 1460

Quoted 5 lines
include/linux/filter.h +1 -1
@@ -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)

No.
Please search the earlier threads where this was discussed. The patches to fix this were posted and I think they landed in some tree already.

pw-bot: cr

#5 lore raw
In reply to Maurice Hieronymus
Quoted 18 lines · Maurice Hieronymus

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.

Changes to v3:
- Split the changes into separate ftrace and bpf patches
- Replace IS_ENABLED() with plain #ifdef

Maurice Hieronymus (2):
  kallsyms: Always initialize modbuildid on ftrace address
  kallsyms: Always initialize modbuildid on bpf address

Quoted 8 lines

 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(-)

base-commit: dd9b004b7ff3289fb7bae35130c0a5c0537266af

This patch is obsolete and already fixed by [1]

[1]
https://lore.kernel.org/bpf/[email protected]/#t