Skip to content

Commit 3908fcd

Browse files
fomichevAlexei Starovoitov
authored andcommitted
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>
1 parent ab850ab commit 3908fcd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

kernel/bpf/bpf_lsm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ BTF_ID(func, bpf_lsm_socket_post_create)
6363
BTF_ID(func, bpf_lsm_socket_socketpair)
6464
BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks)
6565

66+
#ifdef CONFIG_CGROUP_BPF
6667
void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
6768
bpf_func_t *bpf_func)
6869
{
69-
const struct btf_param *args;
70+
const struct btf_param *args __maybe_unused;
7071

7172
if (btf_type_vlen(prog->aux->attach_func_proto) < 1 ||
7273
btf_id_set_contains(&bpf_lsm_current_hooks,
@@ -75,9 +76,9 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
7576
return;
7677
}
7778

79+
#ifdef CONFIG_NET
7880
args = btf_params(prog->aux->attach_func_proto);
7981

80-
#ifdef CONFIG_NET
8182
if (args[0].type == btf_sock_ids[BTF_SOCK_TYPE_SOCKET])
8283
*bpf_func = __cgroup_bpf_run_lsm_socket;
8384
else if (args[0].type == btf_sock_ids[BTF_SOCK_TYPE_SOCK])
@@ -86,6 +87,7 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
8687
#endif
8788
*bpf_func = __cgroup_bpf_run_lsm_current;
8889
}
90+
#endif
8991

9092
int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
9193
const struct bpf_prog *prog)
@@ -219,6 +221,7 @@ bpf_lsm_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
219221
case BPF_FUNC_get_retval:
220222
return prog->expected_attach_type == BPF_LSM_CGROUP ?
221223
&bpf_get_retval_proto : NULL;
224+
#ifdef CONFIG_NET
222225
case BPF_FUNC_setsockopt:
223226
if (prog->expected_attach_type != BPF_LSM_CGROUP)
224227
return NULL;
@@ -239,6 +242,7 @@ bpf_lsm_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
239242
prog->aux->attach_btf_id))
240243
return &bpf_unlocked_sk_getsockopt_proto;
241244
return NULL;
245+
#endif
242246
default:
243247
return tracing_prog_func_proto(func_id, prog);
244248
}

kernel/bpf/trampoline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ int bpf_trampoline_unlink_prog(struct bpf_tramp_link *link, struct bpf_trampolin
501501
return err;
502502
}
503503

504-
#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
504+
#if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_BPF_LSM)
505505
static void bpf_shim_tramp_link_release(struct bpf_link *link)
506506
{
507507
struct bpf_shim_tramp_link *shim_link =

0 commit comments

Comments
 (0)