From: Petr Mladek <pmladek@suse.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Petr Pavlu <petr.pavlu@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Alexei Starovoitov <ast@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
LKML <linux-kernel@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
linux-modules@vger.kernel.org,
linux-trace-kernel <linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/6] kallsyms/bpf: Set module buildid in bpf_address_lookup()
Date: Fri, 7 Nov 2025 14:08:40 +0100 [thread overview]
Message-ID: <aQ3vWIqG31BgE4YD@pathway.suse.cz> (raw)
In-Reply-To: <CAADnVQ+kbQ4uwtKjD1DRCf702v0rEthy6hU4COAU9CyU53wTHg@mail.gmail.com>
On Wed 2025-11-05 18:53:23, Alexei Starovoitov wrote:
> On Wed, Nov 5, 2025 at 6:24 AM Petr Mladek <pmladek@suse.com> wrote:
> >
> > Make bpf_address_lookup() compatible with module_address_lookup()
> > and clear the pointer to @modbuildid together with @modname.
> >
> > It is not strictly needed because __sprint_symbol() reads @modbuildid
> > only when @modname is set. But better be on the safe side and make
> > the API more safe.
> >
> > Fixes: 9294523e3768 ("module: add printk formats to add module build ID to stacktraces")
> > Signed-off-by: Petr Mladek <pmladek@suse.com>
> > ---
> > include/linux/filter.h | 15 +++++++++++----
> > kernel/kallsyms.c | 4 ++--
> > 2 files changed, 13 insertions(+), 6 deletions(-)
> >
> > diff --git a/include/linux/filter.h b/include/linux/filter.h
> > index f5c859b8131a..b7b95840250a 100644
> > --- a/include/linux/filter.h
> > +++ b/include/linux/filter.h
> > @@ -1362,12 +1362,18 @@ 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) {
> > + if (modname)
> > + *modname = NULL;
> > + if (modbuildid)
> > + *modbuildid = NULL;
> > + }
> > +
> > return ret;
> > }
> >
> > @@ -1433,7 +1439,8 @@ 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/kernel/kallsyms.c b/kernel/kallsyms.c
> > index 9455e3bb07fc..efb12b077220 100644
> > --- a/kernel/kallsyms.c
> > +++ b/kernel/kallsyms.c
> > @@ -374,8 +374,8 @@ static int kallsyms_lookup_buildid(unsigned long addr,
> > ret = module_address_lookup(addr, symbolsize, offset,
> > modname, modbuildid, namebuf);
> > if (!ret)
> > - ret = bpf_address_lookup(addr, symbolsize,
> > - offset, modname, namebuf);
> > + ret = bpf_address_lookup(addr, symbolsize, offset,
> > + modname, modbuildid, namebuf);
>
> The initial bpf_address_lookup() 8 years ago was trying
> to copy paste args and style of kallsyms_lookup().
> It was odd back then. This change is doubling down on the wrong thing.
> It's really odd to pass a pointer into bpf_address_lookup()
> so it zero initializes it.
> bpf ksyms are in the core kernel. They're never in modules.
> Just call __bpf_address_lookup() here and remove the wrapper.
I agree that it is ugly. It would make sense to initialize the
pointers in kallsyms_lookup_buildid and call there
__bpf_address_lookup() variant. Something like:
static int kallsyms_lookup_buildid(unsigned long addr,
unsigned long *symbolsize,
unsigned long *offset, char **modname,
const unsigned char **modbuildid, char *namebuf)
{
int ret;
if (modname)
*modname = NULL;
if (modbuildid)
*modbuildid = NULL;
namebuf[0] = 0;
[...]
if (!ret)
ret = __bpf_address_lookup(addr, symbolsize, offset, namebuf);
}
As a result bpf_address_lookup() won't have any caller.
And __bpf_address_lookup() would have two callers.
It would make sense to remove bpf_address_lookup() and
rename __bpf_address_lookup() to bpf_address_lookup().
How does that sound?
Would you prefer to do this in one patch or in two steps, please?
Best Regards,
Petr
next prev parent reply other threads:[~2025-11-07 13:08 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
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 [this message]
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=aQ3vWIqG31BgE4YD@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=da.gomez@kernel.org \
--cc=daniel@iogearbox.net \
--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=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
/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;
as well as URLs for NNTP newsgroup(s).