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

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Only add BTF IDs for socket security hooks when CONFIG_SECURITY_NETWORK is on

When CONFIG_SECURITY_NETWORK is disabled, there will be build warnings
from resolve_btfids:

WARN: resolve_btfids: unresolved symbol bpf_lsm_socket_socketpair
......
WARN: resolve_btfids: unresolved symbol bpf_lsm_inet_conn_established

Fixing it by wrapping these BTF ID definitions by CONFIG_SECURITY_NETWORK.

Fixes: 69fd337a975c ("bpf: per-cgroup lsm flavor")
Fixes: 9113d7e48e91 ("bpf: expose bpf_{g,s}etsockopt to lsm cgroup")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20220901065126.3856297-1-houtao@huaweicloud.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Hou Tao and committed by
Martin KaFai Lau
ef331a8d ccf365ea

+6
+6
kernel/bpf/bpf_lsm.c
··· 41 41 */ 42 42 BTF_SET_START(bpf_lsm_current_hooks) 43 43 /* operate on freshly allocated sk without any cgroup association */ 44 + #ifdef CONFIG_SECURITY_NETWORK 44 45 BTF_ID(func, bpf_lsm_sk_alloc_security) 45 46 BTF_ID(func, bpf_lsm_sk_free_security) 47 + #endif 46 48 BTF_SET_END(bpf_lsm_current_hooks) 47 49 48 50 /* List of LSM hooks that trigger while the socket is properly locked. 49 51 */ 50 52 BTF_SET_START(bpf_lsm_locked_sockopt_hooks) 53 + #ifdef CONFIG_SECURITY_NETWORK 51 54 BTF_ID(func, bpf_lsm_socket_sock_rcv_skb) 52 55 BTF_ID(func, bpf_lsm_sock_graft) 53 56 BTF_ID(func, bpf_lsm_inet_csk_clone) 54 57 BTF_ID(func, bpf_lsm_inet_conn_established) 58 + #endif 55 59 BTF_SET_END(bpf_lsm_locked_sockopt_hooks) 56 60 57 61 /* List of LSM hooks that trigger while the socket is _not_ locked, ··· 63 59 * in the early init phase. 64 60 */ 65 61 BTF_SET_START(bpf_lsm_unlocked_sockopt_hooks) 62 + #ifdef CONFIG_SECURITY_NETWORK 66 63 BTF_ID(func, bpf_lsm_socket_post_create) 67 64 BTF_ID(func, bpf_lsm_socket_socketpair) 65 + #endif 68 66 BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks) 69 67 70 68 #ifdef CONFIG_CGROUP_BPF