Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: fix lsm_cgroup build errors on esoteric configs

This particular ones is about having the following:
CONFIG_BPF_LSM=y
# CONFIG_CGROUP_BPF is not set

Also, add __maybe_unused to the args for the !CONFIG_NET cases.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220714185404.3647772-1-sdf@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Stanislav Fomichev and committed by
Alexei Starovoitov
3908fcdd ab850abb

+7 -3
+6 -2
kernel/bpf/bpf_lsm.c
··· 63 63 BTF_ID(func, bpf_lsm_socket_socketpair) 64 64 BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks) 65 65 66 + #ifdef CONFIG_CGROUP_BPF 66 67 void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, 67 68 bpf_func_t *bpf_func) 68 69 { 69 - const struct btf_param *args; 70 + const struct btf_param *args __maybe_unused; 70 71 71 72 if (btf_type_vlen(prog->aux->attach_func_proto) < 1 || 72 73 btf_id_set_contains(&bpf_lsm_current_hooks, ··· 76 75 return; 77 76 } 78 77 78 + #ifdef CONFIG_NET 79 79 args = btf_params(prog->aux->attach_func_proto); 80 80 81 - #ifdef CONFIG_NET 82 81 if (args[0].type == btf_sock_ids[BTF_SOCK_TYPE_SOCKET]) 83 82 *bpf_func = __cgroup_bpf_run_lsm_socket; 84 83 else if (args[0].type == btf_sock_ids[BTF_SOCK_TYPE_SOCK]) ··· 87 86 #endif 88 87 *bpf_func = __cgroup_bpf_run_lsm_current; 89 88 } 89 + #endif 90 90 91 91 int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, 92 92 const struct bpf_prog *prog) ··· 221 219 case BPF_FUNC_get_retval: 222 220 return prog->expected_attach_type == BPF_LSM_CGROUP ? 223 221 &bpf_get_retval_proto : NULL; 222 + #ifdef CONFIG_NET 224 223 case BPF_FUNC_setsockopt: 225 224 if (prog->expected_attach_type != BPF_LSM_CGROUP) 226 225 return NULL; ··· 242 239 prog->aux->attach_btf_id)) 243 240 return &bpf_unlocked_sk_getsockopt_proto; 244 241 return NULL; 242 + #endif 245 243 default: 246 244 return tracing_prog_func_proto(func_id, prog); 247 245 }
+1 -1
kernel/bpf/trampoline.c
··· 501 501 return err; 502 502 } 503 503 504 - #if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL) 504 + #if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_BPF_LSM) 505 505 static void bpf_shim_tramp_link_release(struct bpf_link *link) 506 506 { 507 507 struct bpf_shim_tramp_link *shim_link =