From: Anton Protopopov <a.s.protopopov@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v1 bpf-next 13/18] bpf: Check the return values of fmod_ret programs on found targets
Date: Mon, 9 Nov 2026 13:14:26 +0000 [thread overview]
Message-ID: <avHHMqdiCgT79XWT@mail.gmail.com> (raw)
In-Reply-To: <sashiko-outbox-202293@kernel.org>
On 26/11/06 09:17PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 1 related pre-existing issue it does not
> introduce:
> - [Critical] bpf: use-after-free in check_helper_call() [1]
> --
>
> commit f5e3bd12bcf921a0d31fb8a40c17694ea46d4300
> Author: Anton Protopopov <a.s.protopopov@gmail.com>
>
> bpf: Check the return values of fmod_ret programs on found targets
>
> This commit parses the "bpf_fmodret_retval:" BTF decl tag on fmod_ret
> target functions and verifies that attached fmod_ret programs only return
> 0 or one of the specified error values, while disallowing tail calls and
> freplace extensions on such programs.
>
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 1b58a1796a2e4..71fbb30e4d768 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -13338,6 +13338,14 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
> > }
> >
> > if (func_id == BPF_FUNC_tail_call) {
> > + /*
> > + * The program which a tail call jumps to returns for this one,
> > + * and a program array does not check the values it may return.
> > + */
> > + if (env->prog->aux->fmodret_retvals) {
> > + verbose(env, "tail calls are not allowed in fmod_ret programs with restricted return values\n");
> > + return -EINVAL;
> > + }
> > if (env->cur_state->curframe) {
> > struct bpf_verifier_state *branch;
> >
>
> [Severity: Critical]
> This problem wasn't introduced by this patch, but in check_helper_call(),
> can passing an RCU-protected or iterator-yielded pointer to a pointer-cast
> helper such as bpf_skc_to_tcp_sock() drop its lifetime constraints on
> regs[BPF_REG_0] [1]?
>
> kernel/bpf/verifier.c:check_helper_call() {
> ...
> if (is_ptr_cast_function(func_id) &&
> find_reference_state(env->cur_state, meta.ref_obj.id)) {
> ...
> regs[BPF_REG_0].type &= ~PTR_MAYBE_NULL;
> regs[BPF_REG_0].id = meta.ref_obj.id;
> }
> ...
> }
>
> RET_PTR_TO_BTF_ID initializes regs[BPF_REG_0] without propagating MEM_RCU or
> parent_id from the input argument, and the cast block above only runs when
> find_reference_state() finds an acquired reference. Because RCU-protected
> and iterator-yielded pointers are tracked via MEM_RCU or parent_id rather
> than a reference state, regs[BPF_REG_0] is left as an unconstrained
> PTR_TO_BTF_ID. When the iterator advances or bpf_rcu_read_unlock() is
> called, the parent pointer is invalidated while the cast pointer remains
> trusted, allowing a use-after-free.
Not related to this patchset.
The bug itself looks real, I think it requires a follow up,
will try to not forget to send it.
> [1] https://sashiko.dev/#/bug/linux-97cfbde4-a454-41bd-bdcf-b13a51d2adaa
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261106205523.1765622-1-a.s.protopopov@gmail.com?part=13
next prev parent reply other threads:[~2026-11-09 13:02 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 21:02 [PATCH v1 bpf-next 01/18] bpf: Add BTF ID sets for fmod_ret targets Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 02/18] bpf: Add a btf_id_set8_entry helper Anton Protopopov
2026-11-06 20:58 ` sashiko-bot
2026-11-09 13:02 ` Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 03/18] bpf: Build fmod_ret target sets from BTF decl tags Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 04/18] selftests/bpf: Declare bpf_fentry_test1 in tracing tests Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 05/18] bpf: Declare fmod_ret targets with BTF_FMODRET sets Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 06/18] selftests/bpf: Test fmod_ret BTF decl tags and attach permission Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 07/18] scripts: Add LLVM plugin infrastructure Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 08/18] bpf: Add the bpf_scan_ir LLVM plugin Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 09/18] bpf: Find fmod_ret candidates in bpf_scan_ir Anton Protopopov
2026-11-06 21:02 ` [PATCH v1 bpf-next 10/18] bpf: Allow writes to private stack objects " Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 11/18] bpf: Follow PHIs " Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 12/18] bpf: Follow integer casts " Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 13/18] bpf: Check the return values of fmod_ret programs on found targets Anton Protopopov
2026-11-06 21:17 ` sashiko-bot
2026-11-09 13:14 ` Anton Protopopov [this message]
2026-11-09 13:16 ` Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 14/18] bpf: Require the JIT for fmod_ret programs on found 64-bit targets Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 15/18] resolve_btfids: Tag fmod_ret candidates as targets Anton Protopopov
2026-11-06 21:14 ` sashiko-bot
2026-11-09 13:26 ` Anton Protopopov
2026-11-06 21:50 ` bot+bpf-ci
2026-11-09 13:33 ` Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 16/18] selftests/bpf: Test fmod_ret candidates found by bpf_scan_ir Anton Protopopov
2026-11-06 21:09 ` sashiko-bot
2026-11-09 14:09 ` Anton Protopopov
2026-11-06 21:50 ` bot+bpf-ci
2026-11-09 13:59 ` Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 17/18] selftests/bpf: Enable bpf_scan_ir in the config Anton Protopopov
2026-11-06 21:35 ` bot+bpf-ci
2026-11-09 13:45 ` Anton Protopopov
2026-11-06 21:03 ` [PATCH v1 bpf-next 18/18] bpftool: List and show fmod_ret targets Anton Protopopov
2026-11-06 21:35 ` bot+bpf-ci
2026-11-09 13:40 ` Anton Protopopov
2026-11-09 17:02 ` [PATCH v1 bpf-next 01/18] bpf: Add BTF ID sets for " Anton Protopopov
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=avHHMqdiCgT79XWT@mail.gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=bpf@vger.kernel.org \
--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.