mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 03:35:32 -04:00
bpf: Distinguish function references in policy diagnostics
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. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/bpf/d02e6a6d3b2dc43a207b8ba836ce62497b250dede9252e7409c5212201c794b7@mail.kernel.org Link: https://lore.kernel.org/bpf/20260816015746.2632990-14-memxor@gmail.com
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user