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 0/8] bpf: additional use-cases for untrusted PTR_TO_MEM
Date: Wed, 2 Jul 2025 15:42:01 -0700 [thread overview]
Message-ID: <20250702224209.3300396-1-eddyz87@gmail.com> (raw)
This patch set introduces two usability enhancements leveraging
untrusted pointers to mem:
- When reading a pointer field from a PTR_TO_BTF_ID, the resulting
value is now assumed to be PTR_TO_MEM|MEM_RDONLY|PTR_UNTRUSTED
instead of SCALAR_VALUE, provided the pointer points to a primitive
type.
- __arg_untrusted attribute for global function parameters,
allowed for pointer arguments of both structural and primitive
types:
- For structural types, the attribute produces
PTR_TO_BTF_ID|PTR_UNTRUSTED.
- For primitive types, it yields
PTR_TO_MEM|MEM_RDONLY|PTR_UNTRUSTED.
Here are examples enabled by the series:
struct foo {
int *arr;
};
...
p = bpf_core_cast(..., struct foo);
bpf_for(i, 0, ...) {
... p->arr[i] ... // load at any offset is allowed
}
int memcmp(void *a __arg_untrusted, void *b __arg_untrusted, size_t n) {
bpf_for(i, 0, n)
if (a[i] - b[i]) // load at any offset is allowed
return ...;
return 0;
}
The patch-set was inspired by Anrii's series [1]. The goal of that
series was to define a generic global glob_match function, capable to
accept any pointer type:
__weak int glob_match(const char *pat, const char *str);
char filename_glob[32];
void foo(...) {
...
task = bpf_get_current_task_btf();
filename = task->mm->exe_file->f_path.dentry->d_name.name;
... match_glob(filename_glob, // pointer to map value
filename) ... // scalar
}
At the moment, there is no straightforward way to express such a
function. This patch-set makes it possible to define it as follows:
__weak int glob_match(const char *pat __arg_untrusted,
const char *str __arg_untrusted);
[1] https://github.com/anakryiko/linux/tree/bpf-mem-cast
Eduard Zingerman (8):
bpf: make makr_btf_ld_reg return error for unexpected reg types
bpf: rdonly_untrusted_mem for btf id walk pointer leafs
selftests/bpf: ptr_to_btf_id struct walk ending with primitive pointer
bpf: attribute __arg_untrusted for global function parameters
libbpf: __arg_untrusted in bpf_helpers.h
selftests/bpf: test cases for __arg_untrusted
bpf: support for void/primitive __arg_untrusted global func params
selftests/bpf: tests for __arg_untrusted void * global func params
include/linux/btf.h | 1 +
kernel/bpf/btf.c | 48 +++++++-
kernel/bpf/verifier.c | 78 +++++++++----
tools/lib/bpf/bpf_helpers.h | 1 +
.../selftests/bpf/prog_tests/linked_list.c | 2 +-
.../bpf/progs/mem_rdonly_untrusted.c | 31 +++++
.../bpf/progs/verifier_global_ptr_args.c | 107 ++++++++++++++++++
7 files changed, 239 insertions(+), 29 deletions(-)
--
2.47.1
next 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 Eduard Zingerman [this message]
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 ` [PATCH bpf-next v1 8/8] selftests/bpf: tests for __arg_untrusted void * " Eduard Zingerman
2025-07-04 18:12 ` 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-1-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