On Wed, Nov 05, 2025 at 03:23:16PM +0100, Petr Mladek wrote:
> __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().
> 
> Fixes: 9294523e3768 ("module: add printk formats to add module build ID to 
> stacktraces")
> Signed-off-by: Petr Mladek <[email protected]>
> ---
>  include/linux/ftrace.h | 6 ++++--
>  kernel/kallsyms.c      | 4 ++--
>  kernel/trace/ftrace.c  | 5 ++++-
>  3 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
> index 7ded7df6e9b5..a003cf1b32d0 100644
> --- a/include/linux/ftrace.h
> +++ b/include/linux/ftrace.h
> @@ -87,11 +87,13 @@ 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 efb12b077220..71868a76e9a1 100644
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c
> @@ -378,8 +378,8 @@ static int kallsyms_lookup_buildid(unsigned long addr,
>                                        modname, modbuildid, namebuf);
>  
>       if (!ret)
> -             ret = ftrace_mod_address_lookup(addr, symbolsize,
> -                                             offset, modname, namebuf);
> +             ret = ftrace_mod_address_lookup(addr, symbolsize, offset,
> +                                             modname, modbuildid, namebuf);
>  
>       return ret;
>  }
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 42bd2ba68a82..11f5096fb60c 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -7678,7 +7678,8 @@ 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;
> @@ -7690,6 +7691,8 @@ ftrace_mod_address_lookup(unsigned long addr, unsigned 
> long *size,
>               if (ret) {
>                       if (modname)
>                               *modname = mod_map->mod->name;
> +                     if (modbuildid)
> +                             *modbuildid = module_buildid(mod_map->mod);
>                       break;
>               }
>       }
> -- 
> 2.51.1
> 
> 

Reviewed-by: Aaron Tomlin <[email protected]>

-- 
Aaron Tomlin

Reply via email to