From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v1 13/14] bpf: Distinguish function references in policy diagnostics
Date: Sun, 16 Aug 2026 03:57:41 +0200 [thread overview]
Message-ID: <20260816015746.2632990-14-memxor@gmail.com> (raw)
In-Reply-To: <20260816015746.2632990-1-memxor@gmail.com>
add_subprogs() rejects both BPF-to-BPF calls and BPF_PSEUDO_FUNC loads for
unprivileged programs. The latter loads a subprogram address for use as a
callback, but its Policy report currently describes it as a function call and
suggests avoiding calls that the program does not contain.
Select the operation and suggestion from the instruction kind. Preserve the
existing call wording for BPF_PSEUDO_CALL, and describe BPF_PSEUDO_FUNC as a
BPF function reference.
Link: https://lore.kernel.org/bpf/d02e6a6d3b2dc43a207b8ba836ce62497b250dede9252e7409c5212201c794b7@mail.kernel.org/
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
kernel/bpf/verifier.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d2f08c6612c6..bc7c1163ab1c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2912,6 +2912,7 @@ static int add_subprogs(struct bpf_verifier_env *env)
struct bpf_subprog_info *subprog = env->subprog_info;
int i, ret, insn_cnt = env->prog->len, ex_cb_insn;
struct bpf_insn *insn = env->prog->insnsi;
+ const char *operation, *suggestion;
/* Add entry function. */
ret = add_subprog(env, 0);
@@ -2923,11 +2924,18 @@ static int add_subprogs(struct bpf_verifier_env *env)
continue;
if (!env->bpf_capable) {
+ if (bpf_pseudo_func(insn)) {
+ operation = "BPF function reference";
+ suggestion = "Load this program with the required capability, or avoid BPF function references in unprivileged programs.";
+ } else {
+ operation = "BPF-to-BPF function call";
+ suggestion = "Load this program with the required capability, or avoid BPF-to-BPF function calls in unprivileged programs.";
+ }
verbose(env, "loading/calling other bpf or kernel functions are allowed for CAP_BPF and CAP_SYS_ADMIN\n");
bpf_diag_policy(
- env, i, "BPF-to-BPF function call",
+ env, i, operation,
"loading or calling other BPF functions requires CAP_BPF or CAP_SYS_ADMIN",
- "Load this program with the required capability, or avoid BPF-to-BPF function calls in unprivileged programs.");
+ suggestion);
return -EPERM;
}
--
2.53.0
next prev parent reply other threads:[~2026-08-16 1:58 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 1:57 [PATCH bpf-next v1 00/14] Follow ups for verifier errors set Kumar Kartikeya Dwivedi
2026-08-16 1:57 ` [PATCH bpf-next v1 01/14] bpf: Correct verifier diagnostic attribution for stack reads Kumar Kartikeya Dwivedi
2026-08-16 6:34 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 02/14] selftests/bpf: Test verifier stack-read diagnostic attribution Kumar Kartikeya Dwivedi
2026-08-16 2:45 ` bot+bpf-ci
2026-08-16 6:35 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 03/14] bpf: Preserve R0 lineage across helper calls Kumar Kartikeya Dwivedi
2026-08-16 2:30 ` bot+bpf-ci
2026-08-16 6:12 ` Eduard Zingerman
2026-08-16 6:36 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 04/14] bpf: Drop dead spill diagnostic condition Kumar Kartikeya Dwivedi
2026-08-16 6:39 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 05/14] bpf: Use canonical stack argument names in diagnostics Kumar Kartikeya Dwivedi
2026-08-16 6:40 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 06/14] bpf: Correct kfunc argument diagnostics Kumar Kartikeya Dwivedi
2026-08-16 2:45 ` bot+bpf-ci
2026-08-16 6:50 ` Eduard Zingerman
2026-08-16 6:52 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 07/14] selftests/bpf: Test " Kumar Kartikeya Dwivedi
2026-08-16 6:53 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 08/14] bpf: Report non-sleepable kfunc programs accurately Kumar Kartikeya Dwivedi
2026-08-16 2:30 ` bot+bpf-ci
2026-08-16 7:32 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 09/14] selftests/bpf: Test non-sleepable kfunc context Kumar Kartikeya Dwivedi
2026-08-16 2:30 ` bot+bpf-ci
2026-08-16 7:37 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 10/14] bpf: Correct Program Structure diagnostic context Kumar Kartikeya Dwivedi
2026-08-16 2:45 ` bot+bpf-ci
2026-08-16 7:58 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 11/14] bpf: Preserve source attribution without source text Kumar Kartikeya Dwivedi
2026-08-16 8:01 ` Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 12/14] selftests/bpf: Test Program Structure diagnostic context Kumar Kartikeya Dwivedi
2026-08-16 8:06 ` Eduard Zingerman
2026-08-16 1:57 ` Kumar Kartikeya Dwivedi [this message]
2026-08-16 8:09 ` [PATCH bpf-next v1 13/14] bpf: Distinguish function references in policy diagnostics Eduard Zingerman
2026-08-16 1:57 ` [PATCH bpf-next v1 14/14] selftests/bpf: Test pseudo-function " Kumar Kartikeya Dwivedi
2026-08-16 2:45 ` 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=20260816015746.2632990-14-memxor@gmail.com \
--to=memxor@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=kernel-team@meta.com \
--cc=kkd@meta.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.