From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 04/13] bpf: Add tracing_multi link support for bpf progs
Date: Sun, 09 Aug 2026 15:33:07 +0000 [thread overview]
Message-ID: <20260809153308.5331D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809150111.45000-5-leon.hwang@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A text poke failure during the detachment of a `tracing_multi` link from BPF programs causes a Use-After-Free of the trampoline executable image and a double free.
- [Medium] Trampoline flags are not rolled back when `__bpf_trampoline_link_prog` fails during `bpf_trampoline_multi_attach`, permanently corrupting the state of the shared trampoline.
--
--- Patch [4]: [PATCH bpf-next 04/13] bpf: Add tracing_multi link support for bpf progs ---
commit b93dc01dd11e0331789988b67d9503ac3b565c51
Author: Leon Hwang <leon.hwang@linux.dev>
bpf: Add tracing_multi link support for bpf progs
Similar to the tracing_multi link support for kernel functions, add
support for bpf progs by reusing the 'ids' fields as BTF ids, and adding
fds array to indicate the target bpf prog. Then, for each pair of fd+id,
they will be the attach targets of tracing_multi link.
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index eddd259d37760..fc51ea2428bee 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -1572,12 +1572,23 @@ static int update_fentry_multi(struct bpf_trampoline *tr, u32 orig_flags,
> struct bpf_tramp_image *im, struct ftrace_hash *hash,
> struct bpf_tracing_multi_data *data)
> {
> - unsigned long addr = (unsigned long)(im ? im->image : tr->cur_image->image);
> + if (tr->func.ftrace_managed) {
> + unsigned long addr = (unsigned long)(im ? im->image : tr->cur_image->image);
>
> - if (bpf_trampoline_use_jmp(tr->flags))
> - addr = ftrace_jmp_set(addr);
> + if (bpf_trampoline_use_jmp(tr->flags))
> + addr = ftrace_jmp_set(addr);
> +
> + ftrace_hash_add(hash, data->entry, tr->ip, addr);
> + } else {
> + void *old_addr = tr->cur_image ? tr->cur_image->image : NULL;
> + void *new_addr = im ? im->image : NULL;
> + int ret;
> +
> + ret = bpf_trampoline_update_fentry(tr, orig_flags, old_addr, new_addr);
> + if (ret)
> + return ret;
[Severity: High]
If bpf_trampoline_update_fentry() fails here, we return the error and bypass
updating tr->cur_image. In bpf_trampoline_multi_detach(), if
__bpf_trampoline_unlink_prog() fails, it logs a warning but continues and
unconditionally calls bpf_trampoline_multi_attach_free().
Since tr->cur_image wasn't updated, does bpf_trampoline_multi_attach_free()
end up freeing the currently active executable image, leading to a
use-after-free and a double free on the next attach/detach?
> + }
>
> - ftrace_hash_add(hash, data->entry, tr->ip, addr);
> tr->cur_image = im;
> return 0;
> }
[ ... ]
> @@ -1691,6 +1715,9 @@ int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
> for_each_mnode(mnode, link) {
> bpf_trampoline_multi_attach_init(mnode->trampoline);
>
> + if (progs && progs[i]->aux->tail_call_reachable)
> + mnode->trampoline->flags |= BPF_TRAMP_F_TAIL_CALL_CTX;
> +
[Severity: Medium]
If __bpf_trampoline_link_prog() fails below, the error handler sets
rollback_cnt = i and skips rolling back the current node i.
Does this leave the BPF_TRAMP_F_TAIL_CALL_CTX flag permanently set on the
trampoline?
> data->entry = &mnode->entry;
> err = __bpf_trampoline_link_prog(&mnode->node, mnode->trampoline, NULL,
> &trampoline_multi_ops, data);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260809150111.45000-1-leon.hwang@linux.dev?part=4
next prev parent reply other threads:[~2026-08-09 15:33 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 15:00 [PATCH bpf-next 00/13] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-08-09 15:00 ` [PATCH bpf-next 01/13] bpf: Initialize ftrace_managed in bpf_trampoline_get Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 02/13] bpf: Factor out update_fentry_multi helper Leon Hwang
2026-08-09 15:14 ` sashiko-bot
2026-08-09 15:01 ` [PATCH bpf-next 03/13] bpf: Drop unnecessary ftrace_location() in update_fentry_multi() Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 04/13] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-08-09 15:33 ` sashiko-bot [this message]
2026-08-10 13:13 ` Jiri Olsa
2026-08-11 6:12 ` Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 05/13] libbpf: " Leon Hwang
2026-08-09 15:21 ` sashiko-bot
2026-08-09 15:01 ` [PATCH bpf-next 06/13] bpf: Add tracing_multi link fdinfo " Leon Hwang
2026-08-09 16:20 ` bot+bpf-ci
2026-08-09 15:01 ` [PATCH bpf-next 07/13] bpf: Add tracing_multi link info " Leon Hwang
2026-08-09 15:17 ` sashiko-bot
2026-08-09 15:01 ` [PATCH bpf-next 08/13] selftests/bpf: Add tracing_multi bpf prog attach test Leon Hwang
2026-08-09 15:01 ` [PATCH bpf-next 09/13] selftests/bpf: Add tracing_multi bpf prog attach failure tests Leon Hwang
2026-08-09 15:17 ` sashiko-bot
2026-08-09 15:01 ` [PATCH bpf-next 10/13] selftests/bpf: Add tracing_multi bpf prog cookie test Leon Hwang
2026-08-09 16:20 ` bot+bpf-ci
2026-08-09 15:01 ` [PATCH bpf-next 11/13] selftests/bpf: Add tracing_multi bpf prog rollback test Leon Hwang
2026-08-09 15:21 ` sashiko-bot
2026-08-09 15:01 ` [PATCH bpf-next 12/13] selftests/bpf: Add tracing_multi bpf prog link info test Leon Hwang
2026-08-09 15:29 ` sashiko-bot
2026-08-09 15:01 ` [PATCH bpf-next 13/13] selftests/bpf: Test tailcall with fentry.multi Leon Hwang
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=20260809153308.5331D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=leon.hwang@linux.dev \
--cc=sashiko-reviews@lists.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.