From: Eduard Zingerman <eddyz87@gmail.com>
To: Anton Protopopov <a.s.protopopov@gmail.com>,
Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpf: Fix gotox target validation against CFG
Date: Tue, 09 Jun 2026 10:27:06 -0700 [thread overview]
Message-ID: <b58e49c8f4d2d4d5d1a9a8f27e77b56b04b5a70d.camel@gmail.com> (raw)
In-Reply-To: <aig3p8QFlWv1sFqV@mail.gmail.com>
On Tue, 2026-06-09 at 15:56 +0000, Anton Protopopov wrote:
> On 26/06/09 11:03PM, Nuoqi Gui wrote:
> > CFG construction records the modeled gotox target set in
> > insn_aux_data->jt. It includes INSN_ARRAY maps based on whether the map
> > target is in the current subprog. check_indirect_jump() later validates and
> > follows the current PTR_TO_INSN register's actual INSN_ARRAY map. The
> > verifier does not check that targets copied from that map match the targets
> > that CFG construction modeled for this gotox instruction.
> >
> > This lets one gotox instruction observe two different INSN_ARRAY maps. CFG
> > can select a map whose target is in the current subprog. Another path to
> > the same gotox can carry a PTR_TO_INSN value from a map whose target points
> > at a different subprog. The verifier then accepts an edge absent from the
> > CFG.
> >
> > On x86, gotox becomes a raw indirect jump in the JIT image. Accepting a
> > target not modeled by CFG can enter another subprog without a matching BPF
> > call frame and crash when executed. Validation observed a GPF in
> > bpf_test_run().
> >
> > Fix this by requiring every target copied from the actual PTR_TO_INSN map
> > to be present in the CFG jump table built for the current gotox
> > instruction.
> > Reject the program before pushing verifier states for any unmodeled target.
> >
> > Fixes: 493d9e0d6083 ("bpf, x86: add support for indirect jumps")
> > Signed-off-by: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>
> > ---
> > kernel/bpf/verifier.c | 26 ++++++++++++++++++++++++++
> > 1 file changed, 26 insertions(+)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index ed7ba0e6a9ce..25fa90e731e3 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -17124,6 +17124,23 @@ static int indirect_jump_min_max_index(struct bpf_verifier_env *env,
> > return 0;
> > }
> >
> > +static bool is_cfg_indirect_jump_target(struct bpf_verifier_env *env,
> > + u32 target)
> > +{
> > + struct bpf_iarray *jt = env->insn_aux_data[env->insn_idx].jt;
> > + int i;
> > +
> > + if (!jt)
> > + return false;
> > +
> > + for (i = 0; i < jt->cnt; i++) {
> > + if (jt->items[i] == target)
> > + return true;
> > + }
> > +
> > + return false;
> > +}
> > +
> > /* gotox *dst_reg */
> > static int check_indirect_jump(struct bpf_verifier_env *env, struct bpf_insn *insn)
> > {
> > @@ -17171,6 +17188,15 @@ static int check_indirect_jump(struct bpf_verifier_env *env, struct bpf_insn *in
> > return -EINVAL;
> > }
> >
> > + for (i = 0; i < n; i++) {
> > + if (!is_cfg_indirect_jump_target(env, env->gotox_tmp_buf->items[i])) {
> > + verbose(env,
> > + "gotox target %u from map id=%d is not in the CFG jump table\n",
> > + env->gotox_tmp_buf->items[i], map->id);
> > + return -EINVAL;
> > + }
> > + }
>
> Thanks for reporting the bug.
>
> As for the fix, would it make more sense to either record maps in
> check_cfg or to re-check subfunc boundaries here?
+1 for checking if the jump is within subprog boundaries assumed for the gotox.
> > for (i = 0; i < n - 1; i++) {
> > mark_indirect_target(env, env->gotox_tmp_buf->items[i]);
> > other_branch = push_stack(env, env->gotox_tmp_buf->items[i],
> >
> > --
> > 2.34.1
> >
next prev parent reply other threads:[~2026-06-09 17:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 15:03 [PATCH bpf-next 0/2] " Nuoqi Gui
2026-06-09 15:03 ` [PATCH bpf-next 1/2] " Nuoqi Gui
2026-06-09 15:42 ` bot+bpf-ci
2026-06-09 15:56 ` Anton Protopopov
2026-06-09 17:27 ` Eduard Zingerman [this message]
2026-06-10 12:22 ` Nuoqi Gui
2026-06-09 15:03 ` [PATCH bpf-next 2/2] selftests/bpf: Add cross-subprog gotox target coverage Nuoqi Gui
2026-06-09 15:42 ` bot+bpf-ci
2026-06-09 16:14 ` Anton Protopopov
2026-06-13 9:33 ` [PATCH bpf-next v2 0/2] bpf: Enforce gotox targets against subprog bounds Nuoqi Gui
2026-06-13 9:33 ` [PATCH bpf-next v2 1/2] " Nuoqi Gui
2026-06-21 15:20 ` Yonghong Song
2026-06-22 15:08 ` Anton Protopopov
2026-06-22 18:06 ` Eduard Zingerman
2026-06-13 9:33 ` [PATCH bpf-next v2 2/2] selftests/bpf: Add cross-subprog gotox target coverage Nuoqi Gui
2026-06-13 10:08 ` bot+bpf-ci
2026-06-21 15:21 ` Yonghong Song
2026-06-22 14:40 ` Anton Protopopov
2026-06-23 9:11 ` Nuoqi Gui
2026-06-22 15:17 ` [PATCH bpf-next v2 0/2] bpf: Enforce gotox targets against subprog bounds Anton Protopopov
2026-06-23 8:56 ` Nuoqi Gui
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=b58e49c8f4d2d4d5d1a9a8f27e77b56b04b5a70d.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=a.s.protopopov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gnq25@mails.tsinghua.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/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
Powered by JetHome