From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 21/21] selftests/bpf: Test limits of the load with raw programs
Date: Mon, 16 Nov 2026 21:17:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-217697@kernel.org> (raw)
In-Reply-To: <20261116152626.4032587-22-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] selftests/bpf: unguarded JIT-only xlated imm check in
test_subprogs()
- [Low] selftests/bpf: pipe write fd leak on error path in
test_freezer()
- [Low] selftests/bpf: unchecked fork() in no_limits reads uninitialized
status
--
commit 3c35bcd7e95d13e7559756b6f54585ddac4df9c1
Author: Alexei Starovoitov <ast@kernel.org>
selftests/bpf: Test limits of the load with raw programs
This commit adds BPF selftests covering program loading under signals,
the cgroup freezer, and memory cgroup limits, as well as tests for
syscall program context, large subprogram counts, xlated dumps, kfuncs,
BTF type chains, and a light skeleton with many maps and programs.
> diff --git a/tools/testing/selftests/bpf/prog_tests/no_limits.c b/tools/testing/selftests/bpf/prog_tests/no_limits.c
> new file mode 100644
> index 0000000000000..b949d1db23e6d
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/no_limits.c
> @@ -0,0 +1,465 @@
[ ... ]
> +static int exit_code(pid_t pid)
> +{
> + int status;
> +
> + if (!ASSERT_EQ(waitpid(pid, &status, 0), pid, "wait") ||
> + !ASSERT_TRUE(WIFEXITED(status), "exited"))
> + return -1;
> + return WEXITSTATUS(status);
> +}
[Severity: Low]
Can exit_code() read an uninitialized status if fork() fails in
test_freezer() or load_in_memcg()? When pid is -1, waitpid(-1, &status,
0) fails with ECHILD and returns -1 without writing status, which passes
ASSERT_EQ(-1, -1) and then evaluates WIFEXITED(status) and
WEXITSTATUS(status) on uninitialized stack memory.
> +
> +/* The freezer does not wait for the end of the load. The load starts again after it. */
> +static void test_freezer(int flag)
> +{
> + struct bpf_insn *insns = straight_code(200000);
> + struct bpf_common_attr common = {};
> + union bpf_attr attr = {
> + .prog_type = BPF_PROG_TYPE_SCHED_CLS,
> + .insns = ptr_to_u64(insns),
> + .insn_cnt = 200000,
> + .license = ptr_to_u64("GPL"),
> + };
> + int cg = -1, pipes[2] = { -1, -1 }, fd;
> + char buf[64] = "";
> + pid_t pid;
> +
> + if (!insns || !ASSERT_OK(setup_cgroup_environment(), "setup") ||
> + !ASSERT_OK(pipe(pipes), "pipe"))
> + goto out;
> + cg = create_and_get_cgroup("/no_limits");
> + if (!ASSERT_OK_FD(cg, "cgroup"))
> + goto out;
> + pid = fork();
> + if (!pid) {
> + /* the fd that the prog gets */
> + if (join_parent_cgroup("/no_limits"))
> + _exit(1);
> + fd = dup(pipes[0]);
> + close(fd);
> + if (write(pipes[1], &fd, sizeof(fd)) != sizeof(fd))
> + _exit(2);
> + _exit(syscall(__NR_bpf, BPF_PROG_LOAD | flag, &attr, sizeof(attr), &common,
> + sizeof(common)) != fd ? 3 : 0);
> + }
> + close(pipes[1]);
> + if (ASSERT_EQ(read(pipes[0], &fd, sizeof(fd)), sizeof(fd), "read")) {
> + usleep(10000);
> + ASSERT_OK(write_cgroup_file("/no_limits", "cgroup.freeze", "1"), "freeze");
> + while (!strstr(buf, "frozen 1") &&
> + !read_cgroup_file("/no_limits", "cgroup.events", buf, sizeof(buf)))
> + usleep(1000);
> + snprintf(buf, sizeof(buf), "/proc/%d/fd/%d", pid, fd);
> + ASSERT_ERR(faccessat(AT_FDCWD, buf, F_OK, AT_SYMLINK_NOFOLLOW), "no prog yet");
> + ASSERT_OK(write_cgroup_file("/no_limits", "cgroup.freeze", "0"), "thaw");
> + }
> + ASSERT_OK(exit_code(pid), "load");
> +out:
> + close(pipes[0]);
> + if (cg >= 0)
> + close(cg);
> + cleanup_cgroup_environment();
> + free(insns);
> +}
[Severity: Low]
Does the out path leak pipes[1] if create_and_get_cgroup() fails after
pipe(pipes) succeeds? Also, if an earlier check jumps to out before
pipe(pipes) succeeds, close(pipes[0]) calls close(-1).
[ ... ]
> +/* The number of a subprog does not fit into s16 */
> +static void test_subprogs(void)
> +{
> + const int funcs = 33000, cnt = 4 * funcs + 1;
> + struct bpf_insn *insns = many_funcs(funcs);
> + struct bpf_prog_info info = {};
> + __u32 len = sizeof(info);
> + int fd;
> +
> + if (!insns)
> + return;
> + fd = load(insns, cnt);
> + if (!ASSERT_OK_FD(fd, "load"))
> + goto out;
> + ASSERT_EQ(run(fd), funcs - 1, "retval");
> + info.xlated_prog_len = cnt * sizeof(*insns);
> + info.xlated_prog_insns = ptr_to_u64(insns);
> + if (ASSERT_OK(bpf_prog_get_info_by_fd(fd, &info, &len), "dump"))
> + ASSERT_EQ(insns[funcs - 1].imm, funcs, "subprog");
[Severity: Medium]
Will this assertion fail when BPF JIT is disabled?
When a program is interpreted rather than JIT-compiled,
bpf_fixup_call_args() rewrites pseudo-calls to BPF_JMP | BPF_CALL_ARGS,
and prepare_dump_pseudo_call() dumps bpf_call_args_imm(insn->off) into
insn->imm instead of the target subprogram index:
kernel/bpf/syscall.c:prepare_dump_pseudo_call() {
...
if (insn->code == (BPF_JMP | BPF_CALL_ARGS))
insn->imm = bpf_call_args_imm(insn->off);
else
insn->imm = bpf_prog_find_func(prog, idx + call_off + 1);
...
}
Should test_subprogs() check info.jited_prog_len (or env.jit_enabled)
before asserting that insns[funcs - 1].imm equals funcs?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116152626.4032587-1-alexei.starovoitov@gmail.com?part=21
next prev parent reply other threads:[~2026-11-16 21:17 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 15:26 [PATCH bpf-next v2 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 01/21] bpf: Stop a load only when the loader is killed or has to freeze Alexei Starovoitov
2026-11-16 16:15 ` sashiko-bot
2026-11-16 15:26 ` [PATCH bpf-next v2 02/21] bpf: Fail the load when there is no memory Alexei Starovoitov
2026-11-16 16:06 ` bot+bpf-ci
2026-11-16 15:26 ` [PATCH bpf-next v2 03/21] bpf: Give a syscall program the largest context when it does tail calls Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 04/21] bpf: Do not inline bpf_loop() when its callback is dead code Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 05/21] bpf: Dump programs that have more than 524288 insns Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 06/21] bpf: Resolve BTF structs and arrays first Alexei Starovoitov
2026-11-16 17:40 ` sashiko-bot
2026-11-16 15:26 ` [PATCH bpf-next v2 07/21] bpf: Remove the limits on maps, BTFs and fd_array of a program Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 08/21] bpf: Do not scan all maps for each insn and each subprog Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 09/21] bpf: Remove the limits on kfuncs of a program Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 10/21] bpf: Remove the limits on tables of functions Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 11/21] libbpf: Size the tables of the loader program from the object Alexei Starovoitov
2026-11-16 16:06 ` bot+bpf-ci
2026-11-16 15:26 ` [PATCH bpf-next v2 12/21] bpf: Relax jumps that patches push out of range Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 13/21] bpf: Keep the call graph in lists of edges Alexei Starovoitov
2026-11-16 19:21 ` sashiko-bot
2026-11-16 15:26 ` [PATCH bpf-next v2 14/21] bpf: Find the effects of callees on the call graph Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 15/21] bpf: Link the decl tags of a type Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 16/21] bpf: Remove BPF_MAX_SUBPROGS Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 17/21] bpf: Walk each type once when looking for special fields Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 18/21] bpf: Raise the limit on the length of BTF names Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 19/21] bpf: Find dominators in O(n log n) Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 20/21] selftests/bpf: Test programs above the old limits Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 21/21] selftests/bpf: Test limits of the load with raw programs Alexei Starovoitov
2026-11-16 21:17 ` sashiko-bot [this message]
2026-11-16 19:00 ` [PATCH bpf-next v2 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields 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-217697@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexei.starovoitov@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox