bpf_lsm.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Google LLC.
  4. */
  5. #ifndef _LINUX_BPF_LSM_H
  6. #define _LINUX_BPF_LSM_H
  7. #include <linux/sched.h>
  8. #include <linux/bpf.h>
  9. #include <linux/lsm_hooks.h>
  10. #ifdef CONFIG_BPF_LSM
  11. #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
  12. RET bpf_lsm_##NAME(__VA_ARGS__);
  13. #include <linux/lsm_hook_defs.h>
  14. #undef LSM_HOOK
  15. struct bpf_storage_blob {
  16. struct bpf_local_storage __rcu *storage;
  17. };
  18. extern struct lsm_blob_sizes bpf_lsm_blob_sizes;
  19. int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
  20. const struct bpf_prog *prog);
  21. bool bpf_lsm_is_sleepable_hook(u32 btf_id);
  22. static inline struct bpf_storage_blob *bpf_inode(
  23. const struct inode *inode)
  24. {
  25. if (unlikely(!inode->i_security))
  26. return NULL;
  27. return inode->i_security + bpf_lsm_blob_sizes.lbs_inode;
  28. }
  29. extern const struct bpf_func_proto bpf_inode_storage_get_proto;
  30. extern const struct bpf_func_proto bpf_inode_storage_delete_proto;
  31. void bpf_inode_storage_free(struct inode *inode);
  32. void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func);
  33. #else /* !CONFIG_BPF_LSM */
  34. static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id)
  35. {
  36. return false;
  37. }
  38. static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
  39. const struct bpf_prog *prog)
  40. {
  41. return -EOPNOTSUPP;
  42. }
  43. static inline struct bpf_storage_blob *bpf_inode(
  44. const struct inode *inode)
  45. {
  46. return NULL;
  47. }
  48. static inline void bpf_inode_storage_free(struct inode *inode)
  49. {
  50. }
  51. static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
  52. bpf_func_t *bpf_func)
  53. {
  54. }
  55. #endif /* CONFIG_BPF_LSM */
  56. #endif /* _LINUX_BPF_LSM_H */