From: Woojin Ji <random6.xyz@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Woojin Ji <random6.xyz@gmail.com>
Subject: [PATCH bpf v2 2/2] selftests/bpf: Test out-of-range index bits in bpf_get_func_arg()
Date: Sun, 18 Oct 2026 13:21:42 +0900 [thread overview]
Message-ID: <20261018-get-func-arg-v2-2-048848b3eddf@gmail.com> (raw)
In-Reply-To: <20261018-get-func-arg-v2-0-048848b3eddf@gmail.com>
The inlined expansion of bpf_get_func_arg() bounds-checks only the low 32
bits of the index, so a helper prototype that keeps the upper bits of the
index is needed to reach it.
Add check_wide_index() and call it from the fexit and tp_btf tests. It
drives the helper with indices that have upper bits set and with indices
whose low 32 bits are out of range, and it checks that the destination is
left untouched when the helper reports -EINVAL. Without the previous patch
the wide index is shifted as 64-bit and the load uses an address far
outside the context.
Acked-by: Jiri Olsa <jolsa@kernel.org>
Assisted-by: LLM
Signed-off-by: Woojin Ji <random6.xyz@gmail.com>
---
.../selftests/bpf/progs/get_func_args_test.c | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/get_func_args_test.c b/tools/testing/selftests/bpf/progs/get_func_args_test.c
index 1bf47f64d0967a3543739841201b58b14b4036a7..9b0beb58d88d5bcf1a36a0598695fd02a2cebbcf 100644
--- a/tools/testing/selftests/bpf/progs/get_func_args_test.c
+++ b/tools/testing/selftests/bpf/progs/get_func_args_test.c
@@ -6,6 +6,40 @@
char _license[] SEC("license") = "GPL";
+/* Keep the upper index bits: the inlined expansion must truncate them. */
+static long (*bpf_get_func_arg_wide)(void *ctx, __u64 n, __u64 *value) =
+ (void *)BPF_FUNC_get_func_arg;
+
+/* Both traced functions are called with arguments 2 and 3. */
+static __always_inline int check_wide_index(void *ctx)
+{
+ __u64 a = 0, z = 0xdeadbeefdeadbeefULL;
+ __s64 err;
+ int ok = 1;
+
+ /* The index is truncated to u32, so these select arguments 0 and 1. */
+ err = bpf_get_func_arg_wide(ctx, 1ULL << 32, &a);
+ ok &= err == 0 && ((int)a == 2);
+ err = bpf_get_func_arg_wide(ctx, (1ULL << 32) | 1, &a);
+ ok &= err == 0 && a == 3;
+ err = bpf_get_func_arg_wide(ctx, 1ULL << 59, &a);
+ ok &= err == 0 && ((int)a == 2);
+ err = bpf_get_func_arg_wide(ctx, (1ULL << 59) | 1, &a);
+ ok &= err == 0 && a == 3;
+
+ /* Out of range: -EINVAL and no store into the destination. */
+ err = bpf_get_func_arg_wide(ctx, (1ULL << 32) | 2, &z);
+ ok &= err == -EINVAL && z == 0xdeadbeefdeadbeefULL;
+ err = bpf_get_func_arg_wide(ctx, (1ULL << 32) | 0xffffffffULL, &z);
+ ok &= err == -EINVAL && z == 0xdeadbeefdeadbeefULL;
+ err = bpf_get_func_arg_wide(ctx, (1ULL << 59) | 2, &z);
+ ok &= err == -EINVAL && z == 0xdeadbeefdeadbeefULL;
+ err = bpf_get_func_arg_wide(ctx, (1ULL << 59) | 0xffffffffULL, &z);
+ ok &= err == -EINVAL && z == 0xdeadbeefdeadbeefULL;
+
+ return ok;
+}
+
__u64 test1_result = 0;
SEC("fentry/bpf_fentry_test1")
int BPF_PROG(test1)
@@ -63,6 +97,7 @@ int BPF_PROG(test2)
/* return value */
err = bpf_get_func_ret(ctx, &ret);
test2_result &= err == 0 && ret == 5;
+ test2_result &= check_wide_index(ctx);
return 0;
}
@@ -162,6 +197,7 @@ int BPF_PROG(tp_test2)
/* not valid argument */
err = bpf_get_func_arg(ctx, 2, &z);
test6_result &= err == -EINVAL;
+ test6_result &= check_wide_index(ctx);
return 0;
}
--
2.47.3
next prev parent reply other threads:[~2026-10-18 4:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 4:21 [PATCH bpf v2 0/2] bpf: Zero-extend the index in inlined bpf_get_func_arg() Woojin Ji
2026-10-18 4:21 ` [PATCH bpf v2 1/2] " Woojin Ji
2026-10-18 4:55 ` bot+bpf-ci
2026-10-18 4:21 ` Woojin Ji [this message]
2026-10-18 15:30 ` [PATCH bpf v2 0/2] " 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=20261018-get-func-arg-v2-2-048848b3eddf@gmail.com \
--to=random6.xyz@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@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
all inboxes | Powered by JetHome®