at v6.13 91 lines 2.1 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2 3/* 4 * Copyright (C) 2020 Google LLC. 5 */ 6 7#ifndef _LINUX_BPF_LSM_H 8#define _LINUX_BPF_LSM_H 9 10#include <linux/sched.h> 11#include <linux/bpf.h> 12#include <linux/bpf_verifier.h> 13#include <linux/lsm_hooks.h> 14 15#ifdef CONFIG_BPF_LSM 16 17#define LSM_HOOK(RET, DEFAULT, NAME, ...) \ 18 RET bpf_lsm_##NAME(__VA_ARGS__); 19#include <linux/lsm_hook_defs.h> 20#undef LSM_HOOK 21 22struct bpf_storage_blob { 23 struct bpf_local_storage __rcu *storage; 24}; 25 26extern struct lsm_blob_sizes bpf_lsm_blob_sizes; 27 28int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, 29 const struct bpf_prog *prog); 30 31bool bpf_lsm_is_sleepable_hook(u32 btf_id); 32bool bpf_lsm_is_trusted(const struct bpf_prog *prog); 33 34static inline struct bpf_storage_blob *bpf_inode( 35 const struct inode *inode) 36{ 37 if (unlikely(!inode->i_security)) 38 return NULL; 39 40 return inode->i_security + bpf_lsm_blob_sizes.lbs_inode; 41} 42 43extern const struct bpf_func_proto bpf_inode_storage_get_proto; 44extern const struct bpf_func_proto bpf_inode_storage_delete_proto; 45void bpf_inode_storage_free(struct inode *inode); 46 47void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); 48 49int bpf_lsm_get_retval_range(const struct bpf_prog *prog, 50 struct bpf_retval_range *range); 51#else /* !CONFIG_BPF_LSM */ 52 53static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id) 54{ 55 return false; 56} 57 58static inline bool bpf_lsm_is_trusted(const struct bpf_prog *prog) 59{ 60 return false; 61} 62 63static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, 64 const struct bpf_prog *prog) 65{ 66 return -EOPNOTSUPP; 67} 68 69static inline struct bpf_storage_blob *bpf_inode( 70 const struct inode *inode) 71{ 72 return NULL; 73} 74 75static inline void bpf_inode_storage_free(struct inode *inode) 76{ 77} 78 79static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, 80 bpf_func_t *bpf_func) 81{ 82} 83 84static inline int bpf_lsm_get_retval_range(const struct bpf_prog *prog, 85 struct bpf_retval_range *range) 86{ 87 return -EOPNOTSUPP; 88} 89#endif /* CONFIG_BPF_LSM */ 90 91#endif /* _LINUX_BPF_LSM_H */