From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 18/21] selftests/bpf: Add tracing_multi bpf prog rollback test
Date: Mon, 12 Oct 2026 16:46:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-168428@kernel.org> (raw)
In-Reply-To: <20261012154024.29423-19-leon.hwang@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: selftest tracing_multi rollback logic relies on unreliable FD ordering
--
commit 00cadf9aa091042698069799ffcf7faa2dd5e6a5
Author: Leon Hwang <leon.hwang@linux.dev>
selftests/bpf: Add tracing_multi bpf prog rollback test
This commit adds a rollback test for multi-attach fentry BPF programs. It
sets up two targets, pre-attaches to one, and then verifies that a subsequent
multi-attach to both correctly handles the busy state and rolls back.
> diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> --- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> @@ -1308,6 +1308,67 @@ static void test_attach_api_bpf_prog_fails(void)
[ ... ]
> + first = target_fds[0] < target_fds[1] ? 0 : 1;
> + second = 1 - first;
> + fds[0] = target_fds[first];
> + fds[1] = target_fds[second];
> + ids[0] = target_ids[first];
> + ids[1] = target_ids[second];
[Severity: Medium]
Does this code incorrectly rely on file descriptor order to predict the
kernel's internal sort order?
The kernel sorts the targets based on a computed key derived from the
program ID and BTF ID: ((u64)prog->aux->id << 32) | btf_id. While program
IDs monotonically increase, FD allocation uses the lowest available FD.
If a lower FD becomes available (for example, closed by another thread or
process) between loading the first and second targets, the second target
receives a smaller FD but a larger ID. This reversed order means the test
will incorrectly predict how the kernel sorts the targets.
> +
> + prog_fd = bpf_program__fd(skel->progs.test_fentry);
> + lopts.tracing_multi.ids = &ids[1];
> + lopts.tracing_multi.fds = &fds[1];
> + lopts.tracing_multi.cnt = 1;
> + pre_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &lopts);
> + if (!ASSERT_GE(pre_fd, 0, "pre_attach"))
> + goto cleanup;
> +
> + lopts.tracing_multi.ids = ids;
> + lopts.tracing_multi.fds = fds;
> + lopts.tracing_multi.cnt = ARRAY_SIZE(ids);
> +
> + fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY_MULTI, &lopts);
> + if (!ASSERT_EQ(fd, -EBUSY, "bpf_link_create"))
> + goto cleanup;
> +
> + prog = first == 0 ? skel->progs.target_1 : skel->progs.target_2;
> + if (run_bpf_target(prog, first + 1, "rollback_target"))
> + goto cleanup;
> + ASSERT_EQ(skel->bss->test_result_fentry, 0, "test_result_fentry");
[Severity: Medium]
Can this assertion pass without the rollback path ever being tested?
If the FD order doesn't match the ID order as mentioned above, the test will
pre-attach the element that the kernel sorts first. The kernel will then
fail immediately on the first element of the multi-attach request. Because
it failed on the first element, it never proceeds to attach (or need to roll
back) the other elements.
The test_result_fentry variable remains 0 in this case, meaning this
assertion will pass and silently mask that the rollback path wasn't
actually exercised.
> +
> +cleanup:
> + if (fd >= 0)
> + close(fd);
> + if (pre_fd >= 0)
> + close(pre_fd);
> + tracing_multi_bpf__destroy(skel);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012154024.29423-1-leon.hwang@linux.dev?part=18
next prev parent reply other threads:[~2026-10-12 16:46 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 15:40 [PATCH bpf-next v2 00/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 01/21] bpf: Initialize ftrace_managed in bpf_trampoline_get() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 02/21] bpf: Drop unnecessary ftrace_location() in register/unregister/modify_fentry_multi() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 03/21] bpf, x86: Factor out bpf_arch_text_poke_prepare_insns() helper on x86_64 Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 04/21] bpf, x86: Factor out bpf_arch_text_poke_check_ip() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 05/21] bpf, x86: Introduce bpf_arch_text_poke_batch() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 06/21] bpf: Add bpf_text_poke_batch() helper in trampoline Leon Hwang
2026-10-12 16:11 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 07/21] bpf: Check tgt_prog before is_tracing_multi_id() in verifier Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 08/21] bpf: Move helpers out of CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard in trampoline Leon Hwang
2026-10-12 16:11 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 09/21] bpf: Add bpf_trampoline_multi_prog_attach/detach() Leon Hwang
2026-10-12 16:16 ` sashiko-bot
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 10/21] bpf: Shrink CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard scope for bpf_tracing_multi_attach() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 11/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 12/21] libbpf: " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 13/21] bpf: Add tracing_multi link fdinfo " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 14/21] bpf: Add tracing_multi link info " Leon Hwang
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 16:36 ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 15/21] selftests/bpf: Add tracing_multi bpf prog attach test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 16/21] selftests/bpf: Add tracing_multi bpf prog attach failure tests Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 17/21] selftests/bpf: Add tracing_multi bpf prog cookie test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 18/21] selftests/bpf: Add tracing_multi bpf prog rollback test Leon Hwang
2026-10-12 16:46 ` sashiko-bot [this message]
2026-10-12 15:40 ` [PATCH bpf-next v2 19/21] selftests/bpf: Add tracing_multi bpf prog link info test Leon Hwang
2026-10-12 16:11 ` bot+bpf-ci
2026-10-12 16:43 ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 20/21] selftests/bpf: Test tailcall with fentry.multi Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 21/21] selftests/bpf: Benchmark tracing_multi bpf progs attachment Leon Hwang
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 16:52 ` sashiko-bot
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-168428@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=leon.hwang@linux.dev \
--cc=linux-trace-kernel@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