From: Slava Imameev <slava.imameev@crowdstrike.com>
To: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>
Cc: <martin.lau@linux.dev>, <eddyz87@gmail.com>, <song@kernel.org>,
<yonghong.song@linux.dev>, <john.fastabend@gmail.com>,
<kpsingh@kernel.org>, <sdf@fomichev.me>, <haoluo@google.com>,
<jolsa@kernel.org>, <davem@davemloft.net>, <edumazet@google.com>,
<kuba@kernel.org>, <pabeni@redhat.com>, <horms@kernel.org>,
<shuah@kernel.org>, <linux-kernel@vger.kernel.org>,
<bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>,
<linux-open-source@crowdstrike.com>,
Slava Imameev <slava.imameev@crowdstrike.com>
Subject: [PATCH bpf-next v4 1/2] bpf: Support new pointer param types via SCALAR_VALUE for trampolines
Date: Tue, 3 Mar 2026 20:54:25 +1100 [thread overview]
Message-ID: <20260303095427.38981-2-slava.imameev@crowdstrike.com> (raw)
In-Reply-To: <20260303095427.38981-1-slava.imameev@crowdstrike.com>
Add BPF verifier support for single- and multi-level pointer
parameters and return values in BPF trampolines. The implementation
treats these parameters as SCALAR_VALUE.
The following new single level pointer support is added:
- pointers to enum, 32 and 64
- pointers to functions
The following multi-level pointer support is added:
- multi-level pointers to int
- multi-level pointers to void
- multi-level pointers to enum, 32 and 64
- multi-level pointers to function
- multi-level pointers to structure
This is consistent with the existing pointers to int and void
already treated as SCALAR.
This provides consistent logic for single and multi-level pointers
- if the type is treated as SCALAR for a single level pointer, the
same is applicable for multi-level pointers, except the pointer to
struct which is currently PTR_TO_BTF_ID, but in case of multi-level
pointer it is treated as scalar as the verifier lacks the context
to infer the size of their target memory regions.
Signed-off-by: Slava Imameev <slava.imameev@crowdstrike.com>
---
kernel/bpf/btf.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 4872d2a6c42d..c2d06d2597d6 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6508,11 +6508,30 @@ struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog)
return prog->aux->attach_btf;
}
-static bool is_void_or_int_ptr(struct btf *btf, const struct btf_type *t)
+static bool is_ptr_treated_as_scalar(const struct btf *btf,
+ const struct btf_type *t)
{
- /* skip modifiers */
+ int depth = 1;
+
+ WARN_ON(!btf_type_is_ptr(t));
+
t = btf_type_skip_modifiers(btf, t->type, NULL);
- return btf_type_is_void(t) || btf_type_is_int(t);
+ while (btf_type_is_ptr(t) && depth < MAX_RESOLVE_DEPTH) {
+ depth += 1;
+ t = btf_type_skip_modifiers(btf, t->type, NULL);
+ }
+
+ /*
+ * If it's a single or multilevel pointer to void, int, enum,
+ * or function, it's the same as scalar from the verifier
+ * safety POV. Multilevel pointers to structures are treated as
+ * scalars. The verifier lacks the context to infer the size of
+ * their target memory regions. Either way, no further pointer
+ * walking is allowed.
+ */
+ return btf_type_is_void(t) || btf_type_is_int(t) ||
+ btf_is_any_enum(t) || btf_type_is_func_proto(t) ||
+ (btf_type_is_struct(t) && depth > 1);
}
u32 btf_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto,
@@ -6902,11 +6921,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
}
}
- /*
- * If it's a pointer to void, it's the same as scalar from the verifier
- * safety POV. Either way, no futher pointer walking is allowed.
- */
- if (is_void_or_int_ptr(btf, t))
+ if (is_ptr_treated_as_scalar(btf, t))
return true;
/* this is a pointer to another type */
--
2.34.1
next prev parent reply other threads:[~2026-03-03 9:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 9:54 [PATCH bpf-next v4 0/2] bpf: Add multi-level pointer parameter support for trampolines Slava Imameev
2026-03-03 9:54 ` Slava Imameev [this message]
2026-03-03 20:05 ` [PATCH bpf-next v4 1/2] bpf: Support new pointer param types via SCALAR_VALUE " Eduard Zingerman
2026-03-03 21:49 ` Slava Imameev
2026-03-03 22:43 ` Eduard Zingerman
2026-03-04 0:22 ` Slava Imameev
2026-03-04 0:36 ` Alexei Starovoitov
2026-03-04 0:38 ` Eduard Zingerman
2026-03-10 12:16 ` Slava Imameev
2026-03-10 18:52 ` Eduard Zingerman
2026-03-11 13:07 ` Slava Imameev
2026-03-11 16:31 ` Eduard Zingerman
2026-03-03 9:54 ` [PATCH bpf-next v4 2/2] selftests/bpf: Add trampolines single and multi-level pointer params test coverage Slava Imameev
2026-03-03 20:08 ` Eduard Zingerman
2026-03-03 22:14 ` Slava Imameev
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=20260303095427.38981-2-slava.imameev@crowdstrike.com \
--to=slava.imameev@crowdstrike.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-open-source@crowdstrike.com \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--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