From: sashiko-bot@kernel.org
To: "Pragyansh Chaturvedi" <r41k0u@ubuntu.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 2/2] selftests/bpf: Test raw_tp test_run ctx padding for tail calls
Date: Sat, 05 Dec 2026 09:25:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-251340@kernel.org> (raw)
In-Reply-To: <20261205090934.3813585-2-r41k0u@ubuntu.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] selftests/bpf: unguarded clang unroll pragma in target()
breaks bpf-gcc
- [Medium] bpf: bpf_prog_test_run_raw_tp() pads tail-call ctx to U16_MAX
instead of 96
- [Low] selftests/bpf: multi-line comments violate BPF comment style
--
commit 8ee6e23e90a8d457fc8e1491da0ce6b2ea624028
Author: Pragyansh Chaturvedi <r41k0u@ubuntu.com>
selftests/bpf: Test raw_tp test_run ctx padding for tail calls
This commit adds the tailcall_raw_tp_ctx subtest to prog_tests/tailcalls.c
and a companion BPF program in progs/tailcall_raw_tp_ctx.c. The test runs
a raw_tracepoint caller with an 8-byte ctx via BPF_PROG_TEST_RUN and
checks that a tail-call target reading 96 bytes of ctx sees zeros past the
first 8 bytes.
> diff --git a/tools/testing/selftests/bpf/prog_tests/tailcalls.c b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
> index 88d223110ecd5..be3bb8584947e 100644
> --- a/tools/testing/selftests/bpf/prog_tests/tailcalls.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
> @@ -17,6 +17,42 @@
> #include "tailcall_callback.skel.h"
> #include "tailcall_bpf2bpf2.skel.h"
> #include "tailcall_bpf2bpf_fexit.skel.h"
> +#include "tailcall_raw_tp_ctx.skel.h"
> +
> +/* test_tailcall_raw_tp_ctx checks that a raw_tp program run through
> + * BPF_PROG_TEST_RUN gets a zero-padded ctx when it can be reached by a
> + * tail call. The caller supplies 8 bytes of ctx and tail-calls a
> + * target that reads 96 bytes; without the padding the target reads
> + * out of bounds and (almost surely) non-zero memory, failing the
> + * retval check.
> + */
[Severity: Low]
This isn't a bug, but BPF code uses the modern kernel multi-line comment
style where the opening /* sits on its own line, even when surrounding
code uses the older style. Both this comment and the multi-line comment
in target() in progs/tailcall_raw_tp_ctx.c put text on the opening /*
line.
[ ... ]
> + /* raw_tp test_run does not accept repeat */
> + LIBBPF_OPTS(bpf_test_run_opts, topts,
> + .ctx_in = ctx,
> + .ctx_size_in = 8,
> + );
> + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.caller), &topts);
[Severity: Medium]
Should bpf_prog_test_run_raw_tp() pad the tail-call context to
MAX_BPF_FUNC_ARGS * sizeof(u64) (96 bytes) instead of U16_MAX?
In the preceding patch in this series, commit "bpf: Give a raw_tp
test_run program the largest context when it does tail calls":
net/bpf/test_run.c:bpf_prog_test_run_raw_tp() {
...
/* the target of a tail call can use that much */
if (prog->aux->tail_call_reachable)
size = max_t(u32, size, U16_MAX);
...
}
raw_tp programs can only tail-call other raw_tp programs, and
bpf_tracing_ctx_access() caps their context access at
sizeof(__u64) * MAX_BPF_FUNC_ARGS (96 bytes), matching the ctx_size_in
limit already enforced in bpf_prog_test_run_raw_tp(). Padding to U16_MAX
makes every raw_tp test_run of a tail-calling program allocate and zero
65,535 bytes via kvzalloc() (requiring order-4 pages or a vmalloc
fallback) instead of a 96-byte slab allocation.
[ ... ]
> diff --git a/tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c b/tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c
> new file mode 100644
> index 0000000000000..e8380d19892a7
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c
[ ... ]
> +SEC("raw_tracepoint/sched_switch")
> +int target(void *ctx)
> +{
> + __u64 *a = ctx;
> +
> + /* The test runs the caller with an 8-byte ctx. Everything past
> + * the first u64 must read as zero: without the test_run ctx
> + * padding, these reads are out of bounds and leak whatever
> + * memory follows the small copy.
> + */
> +#pragma clang loop unroll(full)
> + for (int i = 1; i < 12; i++) {
> + if (a[i])
> + return 1;
> + }
[Severity: Medium]
Does this unguarded #pragma clang loop unroll(full) break the
test_progs-bpf_gcc build?
BPF_CFLAGS enables -Wall -Werror and the bpf-gcc build does not pass
-Wno-unknown-pragmas, so bpf-gcc fails with -Werror=unknown-pragmas (and
without -Werror would not be instructed to unroll the loop). Including
bpf_compiler.h and using __pragma_loop_unroll_full handles both Clang and
bpf-gcc.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205090934.3813585-1-r41k0u@ubuntu.com?part=2
next prev parent reply other threads:[~2026-12-05 9:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 9:06 bpf: tail-call targets bypass max_ctx_offset checks (OOB read, KASAN splats) Pragyansh Chaturvedi
2026-12-05 9:09 ` [PATCH bpf 1/2] bpf: Give a raw_tp test_run program the largest context when it does tail calls Pragyansh Chaturvedi
2026-12-05 9:09 ` [PATCH bpf 2/2] selftests/bpf: Test raw_tp test_run ctx padding for " Pragyansh Chaturvedi
2026-12-05 9:25 ` sashiko-bot [this message]
2026-12-05 9:35 ` bot+bpf-ci
2026-12-05 9:26 ` [PATCH bpf 1/2] bpf: Give a raw_tp test_run program the largest context when it does " sashiko-bot
2026-12-05 9:35 ` bot+bpf-ci
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-251340@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=r41k0u@ubuntu.com \
--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