public inbox for linux-modules@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: bot+bpf-ci@kernel.org
Cc: petr.pavlu@suse.com, rostedt@goodmis.org, ast@kernel.org,
	akpm@linux-foundation.org, kees@kernel.org, daniel@iogearbox.net,
	john.fastabend@gmail.com, mhiramat@kernel.org,
	mark.rutland@arm.com, mcgrof@kernel.org, da.gomez@kernel.org,
	samitolvanen@google.com, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, linux-modules@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, andrii@kernel.org,
	martin.lau@kernel.org, eddyz87@gmail.com,
	yonghong.song@linux.dev, clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH 2/6] kallsyms: Cleanup code for appending the module buildid
Date: Fri, 7 Nov 2025 14:14:57 +0100	[thread overview]
Message-ID: <aQ3w0awU61mrS_AF@pathway.suse.cz> (raw)
In-Reply-To: <451acb410ee1ce42f7fb2da9f3b8162708f40788cb849cc0f50851ad16813349@mail.kernel.org>

On Wed 2025-11-05 14:59:53, bot+bpf-ci@kernel.org wrote:
> > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> > index 1e7635864..9455e3bb0 100644
> > --- a/kernel/kallsyms.c
> > +++ b/kernel/kallsyms.c
> > @@ -423,6 +423,37 @@ int lookup_symbol_name(unsigned long addr, char *symname)
> >  	return lookup_module_symbol_name(addr, symname);
> >  }
> >
> > +#ifdef CONFIG_STACKTRACE_BUILD_ID
> > +
> > +static int append_buildid(char *buffer,  const char *modname,
> > +			  const unsigned char *buildid)
> > +{
> > +	if (!modname)
> > +		return 0;
> > +
> > +	if (!buildid) {
> > +		pr_warn_once("Undefined buildid for the module %s\n", modname);
> > +		return 0;
> > +	}
> 
> When ftrace_mod_address_lookup() succeeds in kallsyms_lookup_buildid(),
> it sets *modname but doesn't initialize *modbuildid. This leaves the
> buildid variable uninitialized when __sprint_symbol() calls
> append_buildid().

Just for record. This is a great analyze. This patchset is fixing
this bug in a later patch. ;-)

> Can the check above read uninitialized memory?> 
> Looking at kallsyms_lookup_buildid():
> - module_address_lookup() properly initializes both modname and
>   modbuildid
> - bpf_address_lookup() sets modname=NULL (so append_buildid isn't
>   called)
> - ftrace_mod_address_lookup() sets modname=mod_map->mod->name but has
>   no modbuildid parameter
> 
> The commit message mentions wanting to catch when lookup functions don't
> handle buildid, but shouldn't kallsyms_lookup_buildid() initialize
> *modbuildid=NULL before calling the lookup functions to avoid undefined
> behavior?

It seems that we are going this way, see
https://lore.kernel.org/all/aQ3vWIqG31BgE4YD@pathway.suse.cz/

Best Regards,
Petr

  reply	other threads:[~2025-11-07 13:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05 14:23 [PATCH 0/6] kallsyms: Prevent invalid access when showing module buildid Petr Mladek
2025-11-05 14:23 ` [PATCH 1/6] module: Add helper function for reading module_buildid() Petr Mladek
2025-11-06  8:52   ` Petr Pavlu
2025-11-06 12:54   ` Daniel Gomez
2025-11-05 14:23 ` [PATCH 2/6] kallsyms: Cleanup code for appending the module buildid Petr Mladek
2025-11-05 14:59   ` bot+bpf-ci
2025-11-07 13:14     ` Petr Mladek [this message]
2025-11-07 17:40       ` Alexei Starovoitov
2025-11-05 14:23 ` [PATCH 3/6] kallsyms/bpf: Set module buildid in bpf_address_lookup() Petr Mladek
2025-11-06  2:53   ` Alexei Starovoitov
2025-11-07 13:08     ` Petr Mladek
2025-11-07 17:37       ` Alexei Starovoitov
2025-11-05 14:23 ` [PATCH 4/6] kallsyms/ftrace: Set module buildid in ftrace_mod_address_lookup() Petr Mladek
2025-11-05 16:22   ` Steven Rostedt
2025-11-07 22:49   ` Aaron Tomlin
2025-11-05 14:23 ` [PATCH 5/6] kallsyms: Clean up @namebuf initialization in kallsyms_lookup_buildid() Petr Mladek
2025-11-07 22:50   ` Aaron Tomlin
2025-11-05 14:23 ` [PATCH 6/6] kallsyms: Prevent module removal when printing module name and buildid Petr Mladek
2025-11-08  0:36   ` Aaron Tomlin
2025-11-10 13:26     ` Petr Mladek
2025-11-11  2:04       ` Aaron Tomlin
2025-11-11  2:18   ` Aaron Tomlin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aQ3w0awU61mrS_AF@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=da.gomez@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox