hooks.c 942 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. LSM_HOOK_INIT(task_free, bpf_task_storage_free),
  15. };
  16. static const struct lsm_id bpf_lsmid = {
  17. .name = "bpf",
  18. .id = LSM_ID_BPF,
  19. };
  20. static int __init bpf_lsm_init(void)
  21. {
  22. security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks),
  23. &bpf_lsmid);
  24. pr_info("LSM support for eBPF active\n");
  25. return 0;
  26. }
  27. struct lsm_blob_sizes bpf_lsm_blob_sizes __ro_after_init = {
  28. .lbs_inode = sizeof(struct bpf_storage_blob),
  29. };
  30. DEFINE_LSM(bpf) = {
  31. .name = "bpf",
  32. .init = bpf_lsm_init,
  33. .blobs = &bpf_lsm_blob_sizes
  34. };