mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 11:03:07 -04:00
libbpf: Skip bpf_object__probe_loading() when BPF token is in use
bpf_object__probe_loading() tries to load trivial SOCKET_FILTER and TRACEPOINT programs to verify the BPF environment works. When a BPF token is in use with restricted program type permissions, these probe loads may fail because the token does not allow the specific program types, even though BPF loading is perfectly functional. Fix by skipping the probe when a token FD is present: BPF token creation itself proves the kernel has a working BPF subsystem. Real BPF issues will be caught during actual program and map loading. Signed-off-by: Yuan Chen <chenyuan@kylinos.cn> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20260610145059.113412-2-chenyuan_fl@163.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
2ce3f548cf
commit
d262a25d8b
@@ -5172,12 +5172,8 @@ bpf_object__probe_loading(struct bpf_object *obj)
|
||||
BPF_EXIT_INSN(),
|
||||
};
|
||||
int ret, insn_cnt = ARRAY_SIZE(insns);
|
||||
LIBBPF_OPTS(bpf_prog_load_opts, opts,
|
||||
.token_fd = obj->token_fd,
|
||||
.prog_flags = obj->token_fd ? BPF_F_TOKEN_FD : 0,
|
||||
);
|
||||
|
||||
if (obj->gen_loader)
|
||||
if (obj->gen_loader || obj->token_fd)
|
||||
return 0;
|
||||
|
||||
ret = bump_rlimit_memlock();
|
||||
@@ -5186,9 +5182,9 @@ bpf_object__probe_loading(struct bpf_object *obj)
|
||||
errstr(ret));
|
||||
|
||||
/* make sure basic loading works */
|
||||
ret = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL", insns, insn_cnt, &opts);
|
||||
ret = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL", insns, insn_cnt, NULL);
|
||||
if (ret < 0)
|
||||
ret = bpf_prog_load(BPF_PROG_TYPE_TRACEPOINT, NULL, "GPL", insns, insn_cnt, &opts);
|
||||
ret = bpf_prog_load(BPF_PROG_TYPE_TRACEPOINT, NULL, "GPL", insns, insn_cnt, NULL);
|
||||
if (ret < 0) {
|
||||
ret = errno;
|
||||
pr_warn("Error in %s(): %s. Couldn't load trivial BPF program. Make sure your kernel supports BPF (CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is set to big enough value.\n",
|
||||
|
||||
Reference in New Issue
Block a user