From: "Nuoqi Gui" <gnq25@mails.tsinghua.edu.cn>
To: "Anton Protopopov" <a.s.protopopov@gmail.com>
Cc: bpf@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Shuah Khan" <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Re: [PATCH bpf-next v2 2/2] selftests/bpf: Add cross-subprog gotox target coverage
Date: Tue, 23 Jun 2026 17:11:25 +0800 (GMT+08:00) [thread overview]
Message-ID: <4ca30c94.85012.19ef3bfae0f.Coremail.gnq25@mails.tsinghua.edu.cn> (raw)
In-Reply-To: <ajlJQUmKUBkNcezW@mail.gmail.com>
> -----Original Messages-----
> From: "Anton Protopopov" <a.s.protopopov@gmail.com>
> Send time:Monday, 22/06/2026 22:40:01
> To: "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>, "Eduard Zingerman" <eddyz87@gmail.com>, "Shuah Khan" <shuah@kernel.org>, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
> Subject: Re: [PATCH bpf-next v2 2/2] selftests/bpf: Add cross-subprog gotox target coverage
>
> On 26/06/13 05:33PM, Nuoqi Gui wrote:
> > Add a gotox regression test with two one-entry INSN_ARRAY maps. CFG can
> > model a map whose target stays in the main subprog, while the verified path
> > can load a different map whose target is the first instruction of another
> > subprog.
> >
> > That second target is outside the subprog that contains this gotox
> > instruction, so program load must be rejected with -EINVAL.
> >
> > Signed-off-by: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>
>
> Sorry, was AFK the last week. The looks better now. A few small nits.
>
> > ---
> > tools/testing/selftests/bpf/prog_tests/bpf_gotox.c | 73 ++++++++++++++++++++++
> > 1 file changed, 73 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c b/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
> > index 73dc63882b7d..5252ca09689c 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
> > @@ -255,6 +255,30 @@ static int create_jt_map(__u32 max_entries)
> > key_size, value_size, max_entries, NULL);
> > }
> >
> > +static int create_jt_map_with_target(__u32 target)
> > +{
> > + struct bpf_insn_array_value val = { .orig_off = target };
> > + __u32 key = 0;
> > + int map_fd;
> > +
> > + map_fd = create_jt_map(1);
> > + if (!ASSERT_GE(map_fd, 0, "create_jt_map"))
> > + return -1;
> > +
> > + if (!ASSERT_EQ(bpf_map_update_elem(map_fd, &key, &val, 0),
> > + 0, "bpf_map_update_elem")) {
> > + close(map_fd);
> > + return -1;
> > + }
> > +
> > + if (!ASSERT_EQ(bpf_map_freeze(map_fd), 0, "bpf_map_freeze")) {
> > + close(map_fd);
> > + return -1;
> > + }
> > +
> > + return map_fd;
> > +}
> > +
> > static int prog_load(struct bpf_insn *insns, __u32 insn_cnt)
> > {
> > return bpf_prog_load(BPF_PROG_TYPE_RAW_TRACEPOINT, NULL, "GPL", insns, insn_cnt, NULL);
> > @@ -393,6 +417,52 @@ reject_offsets(struct bpf_insn *insns, __u32 insn_cnt, int off1, int off2, int o
> > close(prog_fd);
> > }
> >
> > +static void
> > +check_cross_subprog_gotox_target(struct bpf_gotox *skel __always_unused)
>
> Why to pass the skel pointer at all?
>
> > +{
> > + struct bpf_insn insns[] = {
> > + /* main subprog [0,14) */
> > + BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
> > + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_CALL, 0, 12),
> > + BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6, 0),
> > + BPF_JMP_IMM(BPF_JEQ, BPF_REG_7, 0, 4),
> > + BPF_LD_IMM64_RAW(BPF_REG_2, BPF_PSEUDO_MAP_VALUE, 0),
> > + BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, 0),
> > + BPF_JMP_A(3),
> > + BPF_LD_IMM64_RAW(BPF_REG_2, BPF_PSEUDO_MAP_VALUE, 0),
> > + BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, 0),
> > + BPF_RAW_INSN(BPF_JMP | BPF_JA | BPF_X, BPF_REG_2, 0, 0, 0),
> > + BPF_MOV64_IMM(BPF_REG_0, 1),
> > + BPF_EXIT_INSN(),
> > +
> > + /* static subprog [14,16) */
> > + BPF_MOV64_IMM(BPF_REG_0, 42),
> > + BPF_EXIT_INSN(),
> > + };
> > + int good_fd, bad_fd, prog_fd;
> > +
> > + good_fd = create_jt_map_with_target(12);
> > + if (!ASSERT_GE(good_fd, 0, "create_good_jt_map"))
> > + return;
> > +
> > + bad_fd = create_jt_map_with_target(14);
> > + if (!ASSERT_GE(bad_fd, 0, "create_bad_jt_map")) {
> > + close(good_fd);
> > + return;
> > + }
> > +
> > + insns[4].imm = bad_fd;
> > + insns[8].imm = good_fd;
> > +
> > + prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
> > + insns, ARRAY_SIZE(insns), NULL);
> > + if (!ASSERT_EQ(prog_fd, -EINVAL, "cross_subprog_gotox_prog_load"))
> > + close(prog_fd);
> > +
> > + close(bad_fd);
> > + close(good_fd);
> > +}
> > +
> > /*
> > * Verify a bit more complex programs which include indirect jumps
> > * and with jump tables loaded with a non-zero offset
> > @@ -538,6 +608,9 @@ void test_bpf_gotox(void)
> > if (test__start_subtest("check-ldimm64-off-gotox"))
> > __subtest(skel, check_ldimm64_off_gotox);
> >
> > + if (test__start_subtest("check-cross-subprog-gotox-target"))
> > + check_cross_subprog_gotox_target(skel);
> > +
> > if (test__start_subtest("check-ldimm64-off-gotox-llvm"))
> > __subtest(skel, check_ldimm64_off_gotox_llvm);
> >
>
> Why haven't you add the test as the last one? Especially that it
> doesn't use the __subtest() helper.
>
> > --
> > 2.34.1
> >
I will drop the unused skel argument and keep this raw-insn
test independent from the skeleton-based __subtest() path.
next prev parent reply other threads:[~2026-06-23 9:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 15:03 [PATCH bpf-next 0/2] bpf: Fix gotox target validation against CFG 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
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 [this message]
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=4ca30c94.85012.19ef3bfae0f.Coremail.gnq25@mails.tsinghua.edu.cn \
--to=gnq25@mails.tsinghua.edu.cn \
--cc=a.s.protopopov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--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