hooks.c 895 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include <uapi/linux/lsm.h>
  8. static struct security_hook_list bpf_lsm_hooks[] __ro_after_init = {
  9. #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
  10. LSM_HOOK_INIT(NAME, bpf_lsm_##NAME),
  11. #include <linux/lsm_hook_defs.h>
  12. #undef LSM_HOOK
  13. LSM_HOOK_INIT(inode_free_security, bpf_inode_storage_free),
  14. };
  15. static const struct lsm_id bpf_lsmid = {
  16. .name = "bpf",
  17. .id = LSM_ID_BPF,
  18. };
  19. static int __init bpf_lsm_init(void)
  20. {
  21. security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks),
  22. &bpf_lsmid);
  23. pr_info("LSM support for eBPF active\n");
  24. return 0;
  25. }
  26. struct lsm_blob_sizes bpf_lsm_blob_sizes __ro_after_init = {
  27. .lbs_inode = sizeof(struct bpf_storage_blob),
  28. };
  29. DEFINE_LSM(bpf) = {
  30. .id = &bpf_lsmid,
  31. .init = bpf_lsm_init,
  32. .blobs = &bpf_lsm_blob_sizes
  33. };