1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright (C) 2020 Google LLC.
7 #ifndef _LINUX_BPF_LSM_H
8 #define _LINUX_BPF_LSM_H
10 #include <linux/sched.h>
11 #include <linux/bpf.h>
12 #include <linux/lsm_hooks.h>
16 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
17 RET bpf_lsm_##NAME(__VA_ARGS__);
18 #include <linux/lsm_hook_defs.h>
21 struct bpf_storage_blob {
22 struct bpf_local_storage __rcu *storage;
25 extern struct lsm_blob_sizes bpf_lsm_blob_sizes;
27 int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
28 const struct bpf_prog *prog);
30 bool bpf_lsm_is_sleepable_hook(u32 btf_id);
32 static inline struct bpf_storage_blob *bpf_inode(
33 const struct inode *inode)
35 if (unlikely(!inode->i_security))
38 return inode->i_security + bpf_lsm_blob_sizes.lbs_inode;
41 static inline struct bpf_storage_blob *bpf_task(
42 const struct task_struct *task)
44 if (unlikely(!task->security))
47 return task->security + bpf_lsm_blob_sizes.lbs_task;
50 extern const struct bpf_func_proto bpf_inode_storage_get_proto;
51 extern const struct bpf_func_proto bpf_inode_storage_delete_proto;
52 extern const struct bpf_func_proto bpf_task_storage_get_proto;
53 extern const struct bpf_func_proto bpf_task_storage_delete_proto;
54 void bpf_inode_storage_free(struct inode *inode);
55 void bpf_task_storage_free(struct task_struct *task);
57 #else /* !CONFIG_BPF_LSM */
59 static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id)
64 static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
65 const struct bpf_prog *prog)
70 static inline struct bpf_storage_blob *bpf_inode(
71 const struct inode *inode)
76 static inline struct bpf_storage_blob *bpf_task(
77 const struct task_struct *task)
82 static inline void bpf_inode_storage_free(struct inode *inode)
86 static inline void bpf_task_storage_free(struct task_struct *task)
90 #endif /* CONFIG_BPF_LSM */
92 #endif /* _LINUX_BPF_LSM_H */