0001
0002
0003
0004
0005
0006
0007 #ifndef _LINUX_BPF_LSM_H
0008 #define _LINUX_BPF_LSM_H
0009
0010 #include <linux/sched.h>
0011 #include <linux/bpf.h>
0012 #include <linux/lsm_hooks.h>
0013
0014 #ifdef CONFIG_BPF_LSM
0015
0016 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
0017 RET bpf_lsm_##NAME(__VA_ARGS__);
0018 #include <linux/lsm_hook_defs.h>
0019 #undef LSM_HOOK
0020
0021 struct bpf_storage_blob {
0022 struct bpf_local_storage __rcu *storage;
0023 };
0024
0025 extern struct lsm_blob_sizes bpf_lsm_blob_sizes;
0026
0027 int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
0028 const struct bpf_prog *prog);
0029
0030 bool bpf_lsm_is_sleepable_hook(u32 btf_id);
0031
0032 static inline struct bpf_storage_blob *bpf_inode(
0033 const struct inode *inode)
0034 {
0035 if (unlikely(!inode->i_security))
0036 return NULL;
0037
0038 return inode->i_security + bpf_lsm_blob_sizes.lbs_inode;
0039 }
0040
0041 extern const struct bpf_func_proto bpf_inode_storage_get_proto;
0042 extern const struct bpf_func_proto bpf_inode_storage_delete_proto;
0043 void bpf_inode_storage_free(struct inode *inode);
0044
0045 void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func);
0046
0047 #else
0048
0049 static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id)
0050 {
0051 return false;
0052 }
0053
0054 static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
0055 const struct bpf_prog *prog)
0056 {
0057 return -EOPNOTSUPP;
0058 }
0059
0060 static inline struct bpf_storage_blob *bpf_inode(
0061 const struct inode *inode)
0062 {
0063 return NULL;
0064 }
0065
0066 static inline void bpf_inode_storage_free(struct inode *inode)
0067 {
0068 }
0069
0070 static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
0071 bpf_func_t *bpf_func)
0072 {
0073 }
0074
0075 #endif
0076
0077 #endif