bpf_lsm.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/bpf.h>
  8. #include <linux/lsm_hooks.h>
  9. #ifdef CONFIG_BPF_LSM
  10. #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
  11. RET bpf_lsm_##NAME(__VA_ARGS__);
  12. #include <linux/lsm_hook_defs.h>
  13. #undef LSM_HOOK
  14. struct bpf_storage_blob {
  15. struct bpf_local_storage __rcu *storage;
  16. };
  17. extern struct lsm_blob_sizes bpf_lsm_blob_sizes;
  18. int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
  19. const struct bpf_prog *prog);
  20. static inline struct bpf_storage_blob *bpf_inode(
  21. const struct inode *inode)
  22. {
  23. if (unlikely(!inode->i_security))
  24. return NULL;
  25. return inode->i_security + bpf_lsm_blob_sizes.lbs_inode;
  26. }
  27. extern const struct bpf_func_proto bpf_inode_storage_get_proto;
  28. extern const struct bpf_func_proto bpf_inode_storage_delete_proto;
  29. void bpf_inode_storage_free(struct inode *inode);
  30. #else /* !CONFIG_BPF_LSM */
  31. static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
  32. const struct bpf_prog *prog)
  33. {
  34. return -EOPNOTSUPP;
  35. }
  36. static inline struct bpf_storage_blob *bpf_inode(
  37. const struct inode *inode)
  38. {
  39. return NULL;
  40. }
  41. static inline void bpf_inode_storage_free(struct inode *inode)
  42. {
  43. }
  44. #endif /* CONFIG_BPF_LSM */
  45. #endif /* _LINUX_BPF_LSM_H */