From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpf: Initialize ftrace_managed in bpf_trampoline_get()
Date: Fri, 16 Oct 2026 14:32:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-174460@kernel.org> (raw)
In-Reply-To: <20261016142014.12420-2-leon.hwang@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: dummy trampoline causes ftrace_managed text corruption
--
commit df0c3beb4928ce14ffbe4b44e2bc365c2a470352
Author: Leon Hwang <leon.hwang@linux.dev>
bpf: Initialize ftrace_managed in bpf_trampoline_get()
This patch removes the dynamic ftrace_location() check from
register_fentry() and instead initializes ftrace_managed in
bpf_trampoline_get() based on whether tr->ip is non-zero.
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 24edb59238f34..17f2a8133f611 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -475,18 +475,11 @@ static int register_fentry(struct bpf_trampoline *tr, struct bpf_tramp_image *im
> void *data __maybe_unused)
> {
> void *new_addr = im->image;
> - void *ip = tr->func.addr;
> - unsigned long faddr;
> int ret;
>
> - faddr = ftrace_location((unsigned long)ip);
> - if (faddr) {
> + if (tr->func.ftrace_managed) {
> if (!tr->fops)
> return -ENOTSUPP;
> - tr->func.ftrace_managed = true;
> - }
> -
> - if (tr->func.ftrace_managed) {
> ret = direct_ops_add(tr, new_addr);
> } else {
> ret = bpf_trampoline_update_fentry(tr, 0, NULL, new_addr);
[Severity: High]
Because ftrace_managed is no longer evaluated dynamically here, is there a
risk of corrupting ftrace-managed text if tr->func.ftrace_managed was
incorrectly cached as false?
If it evaluates to false, register_fentry() falls back to
bpf_trampoline_update_fentry() which does raw text poking.
[ ... ]
> @@ -1286,6 +1279,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key,
>
> memcpy(&tr->func.model, &tgt_info->fmodel, sizeof(tgt_info->fmodel));
> tr->func.addr = (void *)tgt_info->tgt_addr;
> + tr->func.ftrace_managed = tr->ip != 0;
> out:
> trampoline_unlock(tr);
> return tr;
[Severity: High]
Can this assignment incorrectly mark a ftrace-managed target as non-managed
if a concurrent operation creates a dummy trampoline?
If bpf_trampoline_unlink_cgroup_shim() is called for a program that was
never successfully linked to a trampoline, it calls
bpf_trampoline_lookup(key, 0). Since the trampoline doesn't exist, a dummy
trampoline with tr->ip = 0 is temporarily created.
If a concurrent bpf_trampoline_get() targets the same hook during this
window, it finds the dummy trampoline. With this change, it will cache
tr->func.ftrace_managed as false because tr->ip is 0, regardless of the
actual target address.
When register_fentry() then runs, it bypasses direct ops and uses raw
bpf_arch_text_poke() on the address. Could this cause kernel text
corruption?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261016142014.12420-1-leon.hwang@linux.dev?part=1
next prev parent reply other threads:[~2026-10-16 14:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 14:20 [PATCH bpf-next 0/2] bpf: Two trampoline cleanups Leon Hwang
2026-10-16 14:20 ` [PATCH bpf-next 1/2] bpf: Initialize ftrace_managed in bpf_trampoline_get() Leon Hwang
2026-10-16 14:32 ` sashiko-bot [this message]
2026-10-16 14:20 ` [PATCH bpf-next 2/2] bpf: Drop unnecessary ftrace_location() in register/unregister/modify_fentry_multi() Leon Hwang
2026-10-16 16:50 ` [PATCH bpf-next 0/2] bpf: Two trampoline cleanups 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=sashiko-outbox-174460@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.