From: Jiri Olsa <olsajiri@gmail.com>
To: Chris Mason <mason@kernel.org>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, song@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, martin.lau@linux.dev, yonghong.song@linux.dev,
emil@etsalapatis.com, ihor.solodrai@linux.dev,
rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com, mjambigi@linux.ibm.com,
petr.pavlu@suse.com, linux-trace-kernel@vger.kernel.org,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf 2/2] bpf: Reject kprobe_multi links on coming modules
Date: Fri, 4 Dec 2026 11:05:47 +0100 [thread overview]
Message-ID: <axKQe6swZjR5d65A@krava> (raw)
In-Reply-To: <20261203202617.31741-3-mason@kernel.org>
On Thu, Dec 03, 2026 at 03:26:17PM -0500, Chris Mason wrote:
> bpf_kprobe_multi_link_release() hits a use-after-free on struct module
> if a probed module fails to load.
>
> get_modules_for_addrs() pins each probed module with try_module_get(),
> which also succeeds in MODULE_STATE_COMING. But the error paths of
> load_module() and do_init_module() free the module without checking
> refcnt:
>
> module load kprobe_multi link
> =========== =================
> complete_formation()
> mod->state = MODULE_STATE_COMING
> bpf_kprobe_multi_link_attach()
> get_modules_for_addrs()
> try_module_get()
> do_init_module()
> mod->init() fails
> free_module()
> bpf_kprobe_multi_link_release()
> module_put()
> /* use after free */
>
> The fix used here is to pin a module only once it is live, as
> btf_try_get_module() does.
I wonder this is a problem in other places as well, like in
trace_event_try_get_ref and possibly other places
jirka
>
> Fixes: e22061b2d309 ("bpf: Take module reference on kprobe_multi link")
> Signed-off-by: Chris Mason <mason@kernel.org>
> ---
> kernel/trace/bpf_trace.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 7ad178c3d04db..dbe68a0805db9 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2780,7 +2780,10 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
> skip_add = true;
> break; /* scoped_guard */
> }
> - if (!try_module_get(mod))
> + /* A failed load frees the module despite references */
> + if (module_is_coming(mod))
> + err = -EBUSY;
> + else if (mod->state != MODULE_STATE_LIVE || !try_module_get(mod))
> err = -EINVAL;
> }
> if (skip_add)
> --
> 2.55.0
>
next prev parent reply other threads:[~2026-12-04 10:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 20:26 [PATCH bpf 0/2] bpf: don't attach links to modules that are still loading Chris Mason
2026-12-03 20:26 ` [PATCH bpf 1/2] bpf: Reject raw tracepoint links on coming modules Chris Mason
2026-12-03 20:26 ` [PATCH bpf 2/2] bpf: Reject kprobe_multi " Chris Mason
2026-12-04 10:05 ` Jiri Olsa [this message]
2026-12-04 15:11 ` Chris Mason
2026-12-04 2:30 ` [PATCH bpf 0/2] bpf: don't attach links to modules that are still loading patchwork-bot+netdevbpf
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=axKQe6swZjR5d65A@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=mjambigi@linux.ibm.com \
--cc=petr.pavlu@suse.com \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.