xref: /openbmc/linux/kernel/bpf/bpf_lsm.c (revision 5416c9ae)
1fc611f47SKP Singh // SPDX-License-Identifier: GPL-2.0
2fc611f47SKP Singh 
3fc611f47SKP Singh /*
4fc611f47SKP Singh  * Copyright (C) 2020 Google LLC.
5fc611f47SKP Singh  */
6fc611f47SKP Singh 
7fc611f47SKP Singh #include <linux/filter.h>
8fc611f47SKP Singh #include <linux/bpf.h>
9fc611f47SKP Singh #include <linux/btf.h>
103f6719c7SKP Singh #include <linux/binfmts.h>
119d3fdea7SKP Singh #include <linux/lsm_hooks.h>
129d3fdea7SKP Singh #include <linux/bpf_lsm.h>
139e4e01dfSKP Singh #include <linux/kallsyms.h>
149e4e01dfSKP Singh #include <linux/bpf_verifier.h>
1530897832SKP Singh #include <net/bpf_sk_storage.h>
1630897832SKP Singh #include <linux/bpf_local_storage.h>
176f64e477SKP Singh #include <linux/btf_ids.h>
1827672f0dSKP Singh #include <linux/ima.h>
1969fd337aSStanislav Fomichev #include <linux/bpf-cgroup.h>
209d3fdea7SKP Singh 
219d3fdea7SKP Singh /* For every LSM hook that allows attachment of BPF programs, declare a nop
229d3fdea7SKP Singh  * function where a BPF program can be attached.
239d3fdea7SKP Singh  */
249d3fdea7SKP Singh #define LSM_HOOK(RET, DEFAULT, NAME, ...)	\
259d3fdea7SKP Singh noinline RET bpf_lsm_##NAME(__VA_ARGS__)	\
269d3fdea7SKP Singh {						\
279d3fdea7SKP Singh 	return DEFAULT;				\
289d3fdea7SKP Singh }
299d3fdea7SKP Singh 
309d3fdea7SKP Singh #include <linux/lsm_hook_defs.h>
319d3fdea7SKP Singh #undef LSM_HOOK
32fc611f47SKP Singh 
336f64e477SKP Singh #define LSM_HOOK(RET, DEFAULT, NAME, ...) BTF_ID(func, bpf_lsm_##NAME)
346f64e477SKP Singh BTF_SET_START(bpf_lsm_hooks)
356f64e477SKP Singh #include <linux/lsm_hook_defs.h>
366f64e477SKP Singh #undef LSM_HOOK
BTF_SET_END(bpf_lsm_hooks)376f64e477SKP Singh BTF_SET_END(bpf_lsm_hooks)
389e4e01dfSKP Singh 
3969fd337aSStanislav Fomichev /* List of LSM hooks that should operate on 'current' cgroup regardless
4069fd337aSStanislav Fomichev  * of function signature.
4169fd337aSStanislav Fomichev  */
4269fd337aSStanislav Fomichev BTF_SET_START(bpf_lsm_current_hooks)
4369fd337aSStanislav Fomichev /* operate on freshly allocated sk without any cgroup association */
44ef331a8dSHou Tao #ifdef CONFIG_SECURITY_NETWORK
4569fd337aSStanislav Fomichev BTF_ID(func, bpf_lsm_sk_alloc_security)
4669fd337aSStanislav Fomichev BTF_ID(func, bpf_lsm_sk_free_security)
47ef331a8dSHou Tao #endif
4869fd337aSStanislav Fomichev BTF_SET_END(bpf_lsm_current_hooks)
4969fd337aSStanislav Fomichev 
509113d7e4SStanislav Fomichev /* List of LSM hooks that trigger while the socket is properly locked.
519113d7e4SStanislav Fomichev  */
529113d7e4SStanislav Fomichev BTF_SET_START(bpf_lsm_locked_sockopt_hooks)
53ef331a8dSHou Tao #ifdef CONFIG_SECURITY_NETWORK
549113d7e4SStanislav Fomichev BTF_ID(func, bpf_lsm_sock_graft)
559113d7e4SStanislav Fomichev BTF_ID(func, bpf_lsm_inet_csk_clone)
569113d7e4SStanislav Fomichev BTF_ID(func, bpf_lsm_inet_conn_established)
57ef331a8dSHou Tao #endif
589113d7e4SStanislav Fomichev BTF_SET_END(bpf_lsm_locked_sockopt_hooks)
599113d7e4SStanislav Fomichev 
609113d7e4SStanislav Fomichev /* List of LSM hooks that trigger while the socket is _not_ locked,
619113d7e4SStanislav Fomichev  * but it's ok to call bpf_{g,s}etsockopt because the socket is still
629113d7e4SStanislav Fomichev  * in the early init phase.
639113d7e4SStanislav Fomichev  */
649113d7e4SStanislav Fomichev BTF_SET_START(bpf_lsm_unlocked_sockopt_hooks)
65ef331a8dSHou Tao #ifdef CONFIG_SECURITY_NETWORK
669113d7e4SStanislav Fomichev BTF_ID(func, bpf_lsm_socket_post_create)
679113d7e4SStanislav Fomichev BTF_ID(func, bpf_lsm_socket_socketpair)
68ef331a8dSHou Tao #endif
699113d7e4SStanislav Fomichev BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks)
709113d7e4SStanislav Fomichev 
713908fcddSStanislav Fomichev #ifdef CONFIG_CGROUP_BPF
7269fd337aSStanislav Fomichev void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
7369fd337aSStanislav Fomichev 			     bpf_func_t *bpf_func)
7469fd337aSStanislav Fomichev {
753908fcddSStanislav Fomichev 	const struct btf_param *args __maybe_unused;
7669fd337aSStanislav Fomichev 
7769fd337aSStanislav Fomichev 	if (btf_type_vlen(prog->aux->attach_func_proto) < 1 ||
7869fd337aSStanislav Fomichev 	    btf_id_set_contains(&bpf_lsm_current_hooks,
7969fd337aSStanislav Fomichev 				prog->aux->attach_btf_id)) {
8069fd337aSStanislav Fomichev 		*bpf_func = __cgroup_bpf_run_lsm_current;
8169fd337aSStanislav Fomichev 		return;
8269fd337aSStanislav Fomichev 	}
8369fd337aSStanislav Fomichev 
843908fcddSStanislav Fomichev #ifdef CONFIG_NET
8569fd337aSStanislav Fomichev 	args = btf_params(prog->aux->attach_func_proto);
8669fd337aSStanislav Fomichev 
8769fd337aSStanislav Fomichev 	if (args[0].type == btf_sock_ids[BTF_SOCK_TYPE_SOCKET])
8869fd337aSStanislav Fomichev 		*bpf_func = __cgroup_bpf_run_lsm_socket;
8969fd337aSStanislav Fomichev 	else if (args[0].type == btf_sock_ids[BTF_SOCK_TYPE_SOCK])
9069fd337aSStanislav Fomichev 		*bpf_func = __cgroup_bpf_run_lsm_sock;
9169fd337aSStanislav Fomichev 	else
9269fd337aSStanislav Fomichev #endif
9369fd337aSStanislav Fomichev 		*bpf_func = __cgroup_bpf_run_lsm_current;
9469fd337aSStanislav Fomichev }
953908fcddSStanislav Fomichev #endif
9669fd337aSStanislav Fomichev 
bpf_lsm_verify_prog(struct bpf_verifier_log * vlog,const struct bpf_prog * prog)979e4e01dfSKP Singh int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
989e4e01dfSKP Singh 			const struct bpf_prog *prog)
999e4e01dfSKP Singh {
1009e4e01dfSKP Singh 	if (!prog->gpl_compatible) {
1019e4e01dfSKP Singh 		bpf_log(vlog,
1029e4e01dfSKP Singh 			"LSM programs must have a GPL compatible license\n");
1039e4e01dfSKP Singh 		return -EINVAL;
1049e4e01dfSKP Singh 	}
1059e4e01dfSKP Singh 
1066f64e477SKP Singh 	if (!btf_id_set_contains(&bpf_lsm_hooks, prog->aux->attach_btf_id)) {
1079e4e01dfSKP Singh 		bpf_log(vlog, "attach_btf_id %u points to wrong type name %s\n",
1089e4e01dfSKP Singh 			prog->aux->attach_btf_id, prog->aux->attach_func_name);
1099e4e01dfSKP Singh 		return -EINVAL;
1109e4e01dfSKP Singh 	}
1119e4e01dfSKP Singh 
1129e4e01dfSKP Singh 	return 0;
1139e4e01dfSKP Singh }
1149e4e01dfSKP Singh 
1153f6719c7SKP Singh /* Mask for all the currently supported BPRM option flags */
1163f6719c7SKP Singh #define BPF_F_BRPM_OPTS_MASK	BPF_F_BPRM_SECUREEXEC
1173f6719c7SKP Singh 
BPF_CALL_2(bpf_bprm_opts_set,struct linux_binprm *,bprm,u64,flags)1183f6719c7SKP Singh BPF_CALL_2(bpf_bprm_opts_set, struct linux_binprm *, bprm, u64, flags)
1193f6719c7SKP Singh {
1203f6719c7SKP Singh 	if (flags & ~BPF_F_BRPM_OPTS_MASK)
1213f6719c7SKP Singh 		return -EINVAL;
1223f6719c7SKP Singh 
1233f6719c7SKP Singh 	bprm->secureexec = (flags & BPF_F_BPRM_SECUREEXEC);
1243f6719c7SKP Singh 	return 0;
1253f6719c7SKP Singh }
1263f6719c7SKP Singh 
1273f6719c7SKP Singh BTF_ID_LIST_SINGLE(bpf_bprm_opts_set_btf_ids, struct, linux_binprm)
1283f6719c7SKP Singh 
129e2c69f3aSArnd Bergmann static const struct bpf_func_proto bpf_bprm_opts_set_proto = {
1303f6719c7SKP Singh 	.func		= bpf_bprm_opts_set,
1313f6719c7SKP Singh 	.gpl_only	= false,
1323f6719c7SKP Singh 	.ret_type	= RET_INTEGER,
1333f6719c7SKP Singh 	.arg1_type	= ARG_PTR_TO_BTF_ID,
1343f6719c7SKP Singh 	.arg1_btf_id	= &bpf_bprm_opts_set_btf_ids[0],
1353f6719c7SKP Singh 	.arg2_type	= ARG_ANYTHING,
1363f6719c7SKP Singh };
1373f6719c7SKP Singh 
BPF_CALL_3(bpf_ima_inode_hash,struct inode *,inode,void *,dst,u32,size)13827672f0dSKP Singh BPF_CALL_3(bpf_ima_inode_hash, struct inode *, inode, void *, dst, u32, size)
13927672f0dSKP Singh {
14027672f0dSKP Singh 	return ima_inode_hash(inode, dst, size);
14127672f0dSKP Singh }
14227672f0dSKP Singh 
bpf_ima_inode_hash_allowed(const struct bpf_prog * prog)14327672f0dSKP Singh static bool bpf_ima_inode_hash_allowed(const struct bpf_prog *prog)
14427672f0dSKP Singh {
14527672f0dSKP Singh 	return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id);
14627672f0dSKP Singh }
14727672f0dSKP Singh 
14827672f0dSKP Singh BTF_ID_LIST_SINGLE(bpf_ima_inode_hash_btf_ids, struct, inode)
14927672f0dSKP Singh 
150e2c69f3aSArnd Bergmann static const struct bpf_func_proto bpf_ima_inode_hash_proto = {
15127672f0dSKP Singh 	.func		= bpf_ima_inode_hash,
15227672f0dSKP Singh 	.gpl_only	= false,
15301685c5bSYonghong Song 	.might_sleep	= true,
15427672f0dSKP Singh 	.ret_type	= RET_INTEGER,
15527672f0dSKP Singh 	.arg1_type	= ARG_PTR_TO_BTF_ID,
15627672f0dSKP Singh 	.arg1_btf_id	= &bpf_ima_inode_hash_btf_ids[0],
15727672f0dSKP Singh 	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
15827672f0dSKP Singh 	.arg3_type	= ARG_CONST_SIZE,
15927672f0dSKP Singh 	.allowed	= bpf_ima_inode_hash_allowed,
16027672f0dSKP Singh };
16127672f0dSKP Singh 
BPF_CALL_3(bpf_ima_file_hash,struct file *,file,void *,dst,u32,size)162174b1694SRoberto Sassu BPF_CALL_3(bpf_ima_file_hash, struct file *, file, void *, dst, u32, size)
163174b1694SRoberto Sassu {
164174b1694SRoberto Sassu 	return ima_file_hash(file, dst, size);
165174b1694SRoberto Sassu }
166174b1694SRoberto Sassu 
167174b1694SRoberto Sassu BTF_ID_LIST_SINGLE(bpf_ima_file_hash_btf_ids, struct, file)
168174b1694SRoberto Sassu 
169174b1694SRoberto Sassu static const struct bpf_func_proto bpf_ima_file_hash_proto = {
170174b1694SRoberto Sassu 	.func		= bpf_ima_file_hash,
171174b1694SRoberto Sassu 	.gpl_only	= false,
17201685c5bSYonghong Song 	.might_sleep	= true,
173174b1694SRoberto Sassu 	.ret_type	= RET_INTEGER,
174174b1694SRoberto Sassu 	.arg1_type	= ARG_PTR_TO_BTF_ID,
175174b1694SRoberto Sassu 	.arg1_btf_id	= &bpf_ima_file_hash_btf_ids[0],
176174b1694SRoberto Sassu 	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
177174b1694SRoberto Sassu 	.arg3_type	= ARG_CONST_SIZE,
178174b1694SRoberto Sassu 	.allowed	= bpf_ima_inode_hash_allowed,
179174b1694SRoberto Sassu };
180174b1694SRoberto Sassu 
BPF_CALL_1(bpf_get_attach_cookie,void *,ctx)1812fcc8241SKui-Feng Lee BPF_CALL_1(bpf_get_attach_cookie, void *, ctx)
1822fcc8241SKui-Feng Lee {
1832fcc8241SKui-Feng Lee 	struct bpf_trace_run_ctx *run_ctx;
1842fcc8241SKui-Feng Lee 
1852fcc8241SKui-Feng Lee 	run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx);
1862fcc8241SKui-Feng Lee 	return run_ctx->bpf_cookie;
1872fcc8241SKui-Feng Lee }
1882fcc8241SKui-Feng Lee 
1892fcc8241SKui-Feng Lee static const struct bpf_func_proto bpf_get_attach_cookie_proto = {
1902fcc8241SKui-Feng Lee 	.func		= bpf_get_attach_cookie,
1912fcc8241SKui-Feng Lee 	.gpl_only	= false,
1922fcc8241SKui-Feng Lee 	.ret_type	= RET_INTEGER,
1932fcc8241SKui-Feng Lee 	.arg1_type	= ARG_PTR_TO_CTX,
1942fcc8241SKui-Feng Lee };
1952fcc8241SKui-Feng Lee 
19630897832SKP Singh static const struct bpf_func_proto *
bpf_lsm_func_proto(enum bpf_func_id func_id,const struct bpf_prog * prog)19730897832SKP Singh bpf_lsm_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
19830897832SKP Singh {
199bed89185SStanislav Fomichev 	const struct bpf_func_proto *func_proto;
200bed89185SStanislav Fomichev 
201bed89185SStanislav Fomichev 	if (prog->expected_attach_type == BPF_LSM_CGROUP) {
202bed89185SStanislav Fomichev 		func_proto = cgroup_common_func_proto(func_id, prog);
203bed89185SStanislav Fomichev 		if (func_proto)
204bed89185SStanislav Fomichev 			return func_proto;
205bed89185SStanislav Fomichev 	}
206bed89185SStanislav Fomichev 
20730897832SKP Singh 	switch (func_id) {
20830897832SKP Singh 	case BPF_FUNC_inode_storage_get:
20930897832SKP Singh 		return &bpf_inode_storage_get_proto;
21030897832SKP Singh 	case BPF_FUNC_inode_storage_delete:
21130897832SKP Singh 		return &bpf_inode_storage_delete_proto;
2125c9d706fSDaniel Borkmann #ifdef CONFIG_NET
21330897832SKP Singh 	case BPF_FUNC_sk_storage_get:
214592a3498SMartin KaFai Lau 		return &bpf_sk_storage_get_proto;
21530897832SKP Singh 	case BPF_FUNC_sk_storage_delete:
216592a3498SMartin KaFai Lau 		return &bpf_sk_storage_delete_proto;
2175c9d706fSDaniel Borkmann #endif /* CONFIG_NET */
2189e7a4d98SKP Singh 	case BPF_FUNC_spin_lock:
2199e7a4d98SKP Singh 		return &bpf_spin_lock_proto;
2209e7a4d98SKP Singh 	case BPF_FUNC_spin_unlock:
2219e7a4d98SKP Singh 		return &bpf_spin_unlock_proto;
2223f6719c7SKP Singh 	case BPF_FUNC_bprm_opts_set:
2233f6719c7SKP Singh 		return &bpf_bprm_opts_set_proto;
22427672f0dSKP Singh 	case BPF_FUNC_ima_inode_hash:
22501685c5bSYonghong Song 		return &bpf_ima_inode_hash_proto;
226174b1694SRoberto Sassu 	case BPF_FUNC_ima_file_hash:
22701685c5bSYonghong Song 		return &bpf_ima_file_hash_proto;
2282fcc8241SKui-Feng Lee 	case BPF_FUNC_get_attach_cookie:
2292fcc8241SKui-Feng Lee 		return bpf_prog_has_trampoline(prog) ? &bpf_get_attach_cookie_proto : NULL;
2303908fcddSStanislav Fomichev #ifdef CONFIG_NET
2319113d7e4SStanislav Fomichev 	case BPF_FUNC_setsockopt:
2329113d7e4SStanislav Fomichev 		if (prog->expected_attach_type != BPF_LSM_CGROUP)
2339113d7e4SStanislav Fomichev 			return NULL;
2349113d7e4SStanislav Fomichev 		if (btf_id_set_contains(&bpf_lsm_locked_sockopt_hooks,
2359113d7e4SStanislav Fomichev 					prog->aux->attach_btf_id))
2369113d7e4SStanislav Fomichev 			return &bpf_sk_setsockopt_proto;
2379113d7e4SStanislav Fomichev 		if (btf_id_set_contains(&bpf_lsm_unlocked_sockopt_hooks,
2389113d7e4SStanislav Fomichev 					prog->aux->attach_btf_id))
2399113d7e4SStanislav Fomichev 			return &bpf_unlocked_sk_setsockopt_proto;
2409113d7e4SStanislav Fomichev 		return NULL;
2419113d7e4SStanislav Fomichev 	case BPF_FUNC_getsockopt:
2429113d7e4SStanislav Fomichev 		if (prog->expected_attach_type != BPF_LSM_CGROUP)
2439113d7e4SStanislav Fomichev 			return NULL;
2449113d7e4SStanislav Fomichev 		if (btf_id_set_contains(&bpf_lsm_locked_sockopt_hooks,
2459113d7e4SStanislav Fomichev 					prog->aux->attach_btf_id))
2469113d7e4SStanislav Fomichev 			return &bpf_sk_getsockopt_proto;
2479113d7e4SStanislav Fomichev 		if (btf_id_set_contains(&bpf_lsm_unlocked_sockopt_hooks,
2489113d7e4SStanislav Fomichev 					prog->aux->attach_btf_id))
2499113d7e4SStanislav Fomichev 			return &bpf_unlocked_sk_getsockopt_proto;
2509113d7e4SStanislav Fomichev 		return NULL;
2513908fcddSStanislav Fomichev #endif
25230897832SKP Singh 	default:
25330897832SKP Singh 		return tracing_prog_func_proto(func_id, prog);
25430897832SKP Singh 	}
25530897832SKP Singh }
25630897832SKP Singh 
257423f1610SKP Singh /* The set of hooks which are called without pagefaults disabled and are allowed
258712b78c6SShuyi Cheng  * to "sleep" and thus can be used for sleepable BPF programs.
259423f1610SKP Singh  */
260423f1610SKP Singh BTF_SET_START(sleepable_lsm_hooks)
BTF_ID(func,bpf_lsm_bpf)261423f1610SKP Singh BTF_ID(func, bpf_lsm_bpf)
262423f1610SKP Singh BTF_ID(func, bpf_lsm_bpf_map)
263423f1610SKP Singh BTF_ID(func, bpf_lsm_bpf_map_alloc_security)
264423f1610SKP Singh BTF_ID(func, bpf_lsm_bpf_map_free_security)
265423f1610SKP Singh BTF_ID(func, bpf_lsm_bpf_prog)
266423f1610SKP Singh BTF_ID(func, bpf_lsm_bprm_check_security)
267423f1610SKP Singh BTF_ID(func, bpf_lsm_bprm_committed_creds)
268423f1610SKP Singh BTF_ID(func, bpf_lsm_bprm_committing_creds)
269423f1610SKP Singh BTF_ID(func, bpf_lsm_bprm_creds_for_exec)
270423f1610SKP Singh BTF_ID(func, bpf_lsm_bprm_creds_from_file)
271423f1610SKP Singh BTF_ID(func, bpf_lsm_capget)
272423f1610SKP Singh BTF_ID(func, bpf_lsm_capset)
273423f1610SKP Singh BTF_ID(func, bpf_lsm_cred_prepare)
274423f1610SKP Singh BTF_ID(func, bpf_lsm_file_ioctl)
275423f1610SKP Singh BTF_ID(func, bpf_lsm_file_lock)
276423f1610SKP Singh BTF_ID(func, bpf_lsm_file_open)
277423f1610SKP Singh BTF_ID(func, bpf_lsm_file_receive)
27878031381SMikko Ylinen 
27978031381SMikko Ylinen #ifdef CONFIG_SECURITY_NETWORK
280423f1610SKP Singh BTF_ID(func, bpf_lsm_inet_conn_established)
28178031381SMikko Ylinen #endif /* CONFIG_SECURITY_NETWORK */
28278031381SMikko Ylinen 
283423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_create)
284423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_free_security)
285423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_getattr)
286423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_getxattr)
287423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_mknod)
288423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_need_killpriv)
289423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_post_setxattr)
290423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_readlink)
291423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_rename)
292423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_rmdir)
293423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_setattr)
294423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_setxattr)
295423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_symlink)
296423f1610SKP Singh BTF_ID(func, bpf_lsm_inode_unlink)
297423f1610SKP Singh BTF_ID(func, bpf_lsm_kernel_module_request)
298df6b3039SRoberto Sassu BTF_ID(func, bpf_lsm_kernel_read_file)
299423f1610SKP Singh BTF_ID(func, bpf_lsm_kernfs_init_security)
30078031381SMikko Ylinen 
30178031381SMikko Ylinen #ifdef CONFIG_KEYS
302423f1610SKP Singh BTF_ID(func, bpf_lsm_key_free)
30378031381SMikko Ylinen #endif /* CONFIG_KEYS */
30478031381SMikko Ylinen 
305423f1610SKP Singh BTF_ID(func, bpf_lsm_mmap_file)
306423f1610SKP Singh BTF_ID(func, bpf_lsm_netlink_send)
307423f1610SKP Singh BTF_ID(func, bpf_lsm_path_notify)
308423f1610SKP Singh BTF_ID(func, bpf_lsm_release_secctx)
309423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_alloc_security)
310423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_eat_lsm_opts)
311423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_kern_mount)
312423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_mount)
313423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_remount)
314423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_set_mnt_opts)
315423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_show_options)
316423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_statfs)
317423f1610SKP Singh BTF_ID(func, bpf_lsm_sb_umount)
318423f1610SKP Singh BTF_ID(func, bpf_lsm_settime)
31978031381SMikko Ylinen 
32078031381SMikko Ylinen #ifdef CONFIG_SECURITY_NETWORK
321423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_accept)
322423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_bind)
323423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_connect)
324423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_create)
325423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_getpeername)
326423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_getpeersec_dgram)
327423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_getsockname)
328423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_getsockopt)
329423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_listen)
330423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_post_create)
331423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_recvmsg)
332423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_sendmsg)
333423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_shutdown)
334423f1610SKP Singh BTF_ID(func, bpf_lsm_socket_socketpair)
33578031381SMikko Ylinen #endif /* CONFIG_SECURITY_NETWORK */
33678031381SMikko Ylinen 
337423f1610SKP Singh BTF_ID(func, bpf_lsm_syslog)
338423f1610SKP Singh BTF_ID(func, bpf_lsm_task_alloc)
33963ee956fSAlexei Starovoitov BTF_ID(func, bpf_lsm_current_getsecid_subj)
3404ebd7651SPaul Moore BTF_ID(func, bpf_lsm_task_getsecid_obj)
341423f1610SKP Singh BTF_ID(func, bpf_lsm_task_prctl)
342423f1610SKP Singh BTF_ID(func, bpf_lsm_task_setscheduler)
343423f1610SKP Singh BTF_ID(func, bpf_lsm_task_to_inode)
344401e64b3SFrederick Lawler BTF_ID(func, bpf_lsm_userns_create)
345423f1610SKP Singh BTF_SET_END(sleepable_lsm_hooks)
346423f1610SKP Singh 
347c0c852ddSYonghong Song BTF_SET_START(untrusted_lsm_hooks)
348c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_bpf_map_free_security)
349c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_bpf_prog_alloc_security)
350c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_bpf_prog_free_security)
351c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_file_alloc_security)
352c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_file_free_security)
353*cc074822SHou Tao #ifdef CONFIG_SECURITY_NETWORK
354c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_sk_alloc_security)
355c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_sk_free_security)
356*cc074822SHou Tao #endif /* CONFIG_SECURITY_NETWORK */
357c0c852ddSYonghong Song BTF_ID(func, bpf_lsm_task_free)
358c0c852ddSYonghong Song BTF_SET_END(untrusted_lsm_hooks)
359c0c852ddSYonghong Song 
360423f1610SKP Singh bool bpf_lsm_is_sleepable_hook(u32 btf_id)
361423f1610SKP Singh {
362423f1610SKP Singh 	return btf_id_set_contains(&sleepable_lsm_hooks, btf_id);
363423f1610SKP Singh }
364423f1610SKP Singh 
bpf_lsm_is_trusted(const struct bpf_prog * prog)365c0c852ddSYonghong Song bool bpf_lsm_is_trusted(const struct bpf_prog *prog)
366c0c852ddSYonghong Song {
367c0c852ddSYonghong Song 	return !btf_id_set_contains(&untrusted_lsm_hooks, prog->aux->attach_btf_id);
368c0c852ddSYonghong Song }
369c0c852ddSYonghong Song 
370fc611f47SKP Singh const struct bpf_prog_ops lsm_prog_ops = {
371fc611f47SKP Singh };
372fc611f47SKP Singh 
373fc611f47SKP Singh const struct bpf_verifier_ops lsm_verifier_ops = {
37430897832SKP Singh 	.get_func_proto = bpf_lsm_func_proto,
375fc611f47SKP Singh 	.is_valid_access = btf_ctx_access,
376fc611f47SKP Singh };
377