1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 3 /* 3 /* 4 * Copyright (C) 2020 Google LLC. 4 * Copyright (C) 2020 Google LLC. 5 */ 5 */ 6 6 7 #ifndef _LINUX_BPF_LSM_H 7 #ifndef _LINUX_BPF_LSM_H 8 #define _LINUX_BPF_LSM_H 8 #define _LINUX_BPF_LSM_H 9 9 10 #include <linux/sched.h> 10 #include <linux/sched.h> 11 #include <linux/bpf.h> 11 #include <linux/bpf.h> 12 #include <linux/bpf_verifier.h> << 13 #include <linux/lsm_hooks.h> 12 #include <linux/lsm_hooks.h> 14 13 15 #ifdef CONFIG_BPF_LSM 14 #ifdef CONFIG_BPF_LSM 16 15 17 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ 16 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ 18 RET bpf_lsm_##NAME(__VA_ARGS__); 17 RET bpf_lsm_##NAME(__VA_ARGS__); 19 #include <linux/lsm_hook_defs.h> 18 #include <linux/lsm_hook_defs.h> 20 #undef LSM_HOOK 19 #undef LSM_HOOK 21 20 22 struct bpf_storage_blob { 21 struct bpf_storage_blob { 23 struct bpf_local_storage __rcu *storag 22 struct bpf_local_storage __rcu *storage; 24 }; 23 }; 25 24 26 extern struct lsm_blob_sizes bpf_lsm_blob_size 25 extern struct lsm_blob_sizes bpf_lsm_blob_sizes; 27 26 28 int bpf_lsm_verify_prog(struct bpf_verifier_lo 27 int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, 29 const struct bpf_prog 28 const struct bpf_prog *prog); 30 29 31 bool bpf_lsm_is_sleepable_hook(u32 btf_id); 30 bool bpf_lsm_is_sleepable_hook(u32 btf_id); 32 bool bpf_lsm_is_trusted(const struct bpf_prog 31 bool bpf_lsm_is_trusted(const struct bpf_prog *prog); 33 32 34 static inline struct bpf_storage_blob *bpf_ino 33 static inline struct bpf_storage_blob *bpf_inode( 35 const struct inode *inode) 34 const struct inode *inode) 36 { 35 { 37 if (unlikely(!inode->i_security)) 36 if (unlikely(!inode->i_security)) 38 return NULL; 37 return NULL; 39 38 40 return inode->i_security + bpf_lsm_blo 39 return inode->i_security + bpf_lsm_blob_sizes.lbs_inode; 41 } 40 } 42 41 43 extern const struct bpf_func_proto bpf_inode_s 42 extern const struct bpf_func_proto bpf_inode_storage_get_proto; 44 extern const struct bpf_func_proto bpf_inode_s 43 extern const struct bpf_func_proto bpf_inode_storage_delete_proto; 45 void bpf_inode_storage_free(struct inode *inod 44 void bpf_inode_storage_free(struct inode *inode); 46 45 47 void bpf_lsm_find_cgroup_shim(const struct bpf 46 void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); 48 47 49 int bpf_lsm_get_retval_range(const struct bpf_ << 50 struct bpf_retval << 51 #else /* !CONFIG_BPF_LSM */ 48 #else /* !CONFIG_BPF_LSM */ 52 49 53 static inline bool bpf_lsm_is_sleepable_hook(u 50 static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id) 54 { 51 { 55 return false; 52 return false; 56 } 53 } 57 54 58 static inline bool bpf_lsm_is_trusted(const st 55 static inline bool bpf_lsm_is_trusted(const struct bpf_prog *prog) 59 { 56 { 60 return false; 57 return false; 61 } 58 } 62 59 63 static inline int bpf_lsm_verify_prog(struct b 60 static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, 64 const st 61 const struct bpf_prog *prog) 65 { 62 { 66 return -EOPNOTSUPP; 63 return -EOPNOTSUPP; 67 } 64 } 68 65 69 static inline struct bpf_storage_blob *bpf_ino 66 static inline struct bpf_storage_blob *bpf_inode( 70 const struct inode *inode) 67 const struct inode *inode) 71 { 68 { 72 return NULL; 69 return NULL; 73 } 70 } 74 71 75 static inline void bpf_inode_storage_free(stru 72 static inline void bpf_inode_storage_free(struct inode *inode) 76 { 73 { 77 } 74 } 78 75 79 static inline void bpf_lsm_find_cgroup_shim(co 76 static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, 80 bpf 77 bpf_func_t *bpf_func) 81 { 78 { 82 } 79 } 83 80 84 static inline int bpf_lsm_get_retval_range(con << 85 str << 86 { << 87 return -EOPNOTSUPP; << 88 } << 89 #endif /* CONFIG_BPF_LSM */ 81 #endif /* CONFIG_BPF_LSM */ 90 82 91 #endif /* _LINUX_BPF_LSM_H */ 83 #endif /* _LINUX_BPF_LSM_H */ 92 84
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.