From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org
Cc: daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yonghong.song@linux.dev, eddyz87@gmail.com
Subject: [PATCH bpf-next v1 8/8] selftests/bpf: tests for __arg_untrusted void * global func params
Date: Wed, 2 Jul 2025 15:42:09 -0700 [thread overview]
Message-ID: <20250702224209.3300396-9-eddyz87@gmail.com> (raw)
In-Reply-To: <20250702224209.3300396-1-eddyz87@gmail.com>
Check usage of __arg_untrusted parameters of primitive type:
- passing of {trusted, untrusted, map value, scalar value, values with
variable offset} to untrusted `void *` or `char *` is ok;
- varifier represents such parameters as rdonly_untrusted_mem(sz=0).
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
.../bpf/progs/verifier_global_ptr_args.c | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c b/tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c
index 772e8dd3e001..f91d9c2906aa 100644
--- a/tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c
+++ b/tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c
@@ -245,4 +245,45 @@ int untrusted_to_trusted(void *ctx)
return subprog_untrusted2(bpf_get_current_task_btf());
}
+__weak int subprog_void_untrusted(void *p __arg_untrusted)
+{
+ return *(int *)p;
+}
+
+__weak int subprog_char_untrusted(char *p __arg_untrusted)
+{
+ return *(int *)p;
+}
+
+SEC("tp_btf/sys_enter")
+__success
+__log_level(2)
+__msg("r1 = {{.*}}; {{.*}}R1_w=trusted_ptr_task_struct()")
+__msg("Func#1 ('subprog_void_untrusted') is global and assumed valid.")
+__msg("Validating subprog_void_untrusted() func#1...")
+__msg(": R1=rdonly_untrusted_mem(sz=0)")
+int trusted_to_untrusted_mem(void *ctx)
+{
+ return subprog_void_untrusted(bpf_get_current_task_btf());
+}
+
+SEC("tp_btf/sys_enter")
+__success
+int anything_to_untrusted_mem(void *ctx)
+{
+ /* untrusted to untrusted mem */
+ subprog_void_untrusted(bpf_core_cast(0, struct task_struct));
+ /* map value to untrusted mem */
+ subprog_void_untrusted(mem);
+ /* scalar to untrusted mem */
+ subprog_void_untrusted(0);
+ /* variable offset to untrusted mem (map) */
+ subprog_void_untrusted((void *)mem + off);
+ /* variable offset to untrusted mem (trusted) */
+ subprog_void_untrusted(bpf_get_current_task_btf() + off);
+ /* variable offset to untrusted char (map) */
+ subprog_char_untrusted(mem + off);
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";
--
2.47.1
next prev parent reply other threads:[~2025-07-02 22:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 22:42 [PATCH bpf-next v1 0/8] bpf: additional use-cases for untrusted PTR_TO_MEM Eduard Zingerman
2025-07-02 22:42 ` [PATCH bpf-next v1 1/8] bpf: make makr_btf_ld_reg return error for unexpected reg types Eduard Zingerman
2025-07-04 17:20 ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 2/8] bpf: rdonly_untrusted_mem for btf id walk pointer leafs Eduard Zingerman
2025-07-04 17:27 ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 3/8] selftests/bpf: ptr_to_btf_id struct walk ending with primitive pointer Eduard Zingerman
2025-07-04 17:34 ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 4/8] bpf: attribute __arg_untrusted for global function parameters Eduard Zingerman
2025-07-03 3:18 ` Alexei Starovoitov
2025-07-03 21:25 ` Eduard Zingerman
2025-07-04 18:17 ` Alexei Starovoitov
2025-07-04 18:03 ` Kumar Kartikeya Dwivedi
2025-07-04 18:28 ` Eduard Zingerman
2025-07-04 18:33 ` Eduard Zingerman
2025-07-04 18:50 ` Kumar Kartikeya Dwivedi
2025-07-04 19:07 ` Eduard Zingerman
2025-07-04 19:15 ` Kumar Kartikeya Dwivedi
2025-07-04 19:23 ` Eduard Zingerman
2025-07-04 20:05 ` Alexei Starovoitov
2025-07-04 20:20 ` Kumar Kartikeya Dwivedi
2025-07-04 20:34 ` Eduard Zingerman
2025-07-04 20:47 ` Alexei Starovoitov
2025-07-02 22:42 ` [PATCH bpf-next v1 5/8] libbpf: __arg_untrusted in bpf_helpers.h Eduard Zingerman
2025-07-04 18:04 ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 6/8] selftests/bpf: test cases for __arg_untrusted Eduard Zingerman
2025-07-04 18:05 ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 7/8] bpf: support for void/primitive __arg_untrusted global func params Eduard Zingerman
2025-07-03 3:20 ` Alexei Starovoitov
2025-07-03 21:49 ` Eduard Zingerman
2025-07-04 18:11 ` Alexei Starovoitov
2025-07-04 18:09 ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` Eduard Zingerman [this message]
2025-07-04 18:12 ` [PATCH bpf-next v1 8/8] selftests/bpf: tests for __arg_untrusted void * " Kumar Kartikeya Dwivedi
2025-07-04 18:35 ` Eduard Zingerman
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=20250702224209.3300396-9-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--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