kallsyms: Always initialize modbuildid
PATCH v3 1/1 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 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(-)
include/linux/filter.h +4 -2
@@ -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 ; }
include/linux/ftrace.h +2 -2
@@ -87,11 +87,11 @@ struct ftrace_hash;defined (CONFIG_DYNAMIC_FTRACE) intftrace_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 +2 -2
@@ -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; }
kernel/trace/ftrace.c +7 -1
@@ -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
Signature · 1 line
2.50.1
Steven Rostedt
maintainerkernel/trace/ftrace.c ftrace_mod_address_lookup(unsigned long addr, unsigned long *size, · line 7765
Quoted 6 lines · On Wed, 10 Dec 2025 18:03:45 +0100 Maurice Hieronymus <[email protected]> wrote:
kernel/trace/ftrace.c +2
-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)
IS_ENABLED() is for use within C code. This should simply be:
#ifdef CONFIG_STACKTRACE_BUILD_ID
-- Steve
Quoted 7 lines
kernel/trace/ftrace.c +4
-0+ *modbuildid = mod_map->mod->build_id; +#else + *modbuildid =NULL ; +#endif break ; } }
Steven Rostedt
maintainerQuoted 5 lines · On Wed, 10 Dec 2025 18:03:45 +0100 Maurice Hieronymus <[email protected]> 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