hooks.c 781 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020 Google LLC.
  4. */
  5. #include <linux/lsm_hooks.h>
  6. #include <linux/bpf_lsm.h>
  7. static struct security_hook_list bpf_lsm_hooks[] __lsm_ro_after_init = {
  8. #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
  9. LSM_HOOK_INIT(NAME, bpf_lsm_##NAME),
  10. #include <linux/lsm_hook_defs.h>
  11. #undef LSM_HOOK
  12. LSM_HOOK_INIT(inode_free_security, bpf_inode_storage_free),
  13. };
  14. static int __init bpf_lsm_init(void)
  15. {
  16. security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks), "bpf");
  17. pr_info("LSM support for eBPF active\n");
  18. return 0;
  19. }
  20. struct lsm_blob_sizes bpf_lsm_blob_sizes __lsm_ro_after_init = {
  21. .lbs_inode = sizeof(struct bpf_storage_blob),
  22. };
  23. DEFINE_LSM(bpf) = {
  24. .name = "bpf",
  25. .init = bpf_lsm_init,
  26. .blobs = &bpf_lsm_blob_sizes
  27. };