setup.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Landlock LSM - Security framework setup
  4. *
  5. * Copyright © 2016-2020 Mickaël Salaün <mic@digikod.net>
  6. * Copyright © 2018-2020 ANSSI
  7. */
  8. #include <linux/bits.h>
  9. #include <linux/init.h>
  10. #include <linux/lsm_hooks.h>
  11. #include <uapi/linux/lsm.h>
  12. #include "common.h"
  13. #include "cred.h"
  14. #include "errata.h"
  15. #include "fs.h"
  16. #include "net.h"
  17. #include "setup.h"
  18. #include "task.h"
  19. bool landlock_initialized __ro_after_init = false;
  20. const struct lsm_id landlock_lsmid = {
  21. .name = LANDLOCK_NAME,
  22. .id = LSM_ID_LANDLOCK,
  23. };
  24. struct lsm_blob_sizes landlock_blob_sizes __ro_after_init = {
  25. .lbs_cred = sizeof(struct landlock_cred_security),
  26. .lbs_file = sizeof(struct landlock_file_security),
  27. .lbs_inode = sizeof(struct landlock_inode_security),
  28. .lbs_superblock = sizeof(struct landlock_superblock_security),
  29. };
  30. int landlock_errata __ro_after_init;
  31. static void __init compute_errata(void)
  32. {
  33. size_t i;
  34. #ifndef __has_include
  35. /*
  36. * This is a safeguard to make sure the compiler implements
  37. * __has_include (see errata.h).
  38. */
  39. WARN_ON_ONCE(1);
  40. return;
  41. #endif
  42. for (i = 0; landlock_errata_init[i].number; i++) {
  43. const int prev_errata = landlock_errata;
  44. if (WARN_ON_ONCE(landlock_errata_init[i].abi >
  45. landlock_abi_version))
  46. continue;
  47. landlock_errata |= BIT(landlock_errata_init[i].number - 1);
  48. WARN_ON_ONCE(prev_errata == landlock_errata);
  49. }
  50. }
  51. static int __init landlock_init(void)
  52. {
  53. compute_errata();
  54. landlock_add_cred_hooks();
  55. landlock_add_task_hooks();
  56. landlock_add_fs_hooks();
  57. landlock_add_net_hooks();
  58. landlock_initialized = true;
  59. pr_info("Up and running.\n");
  60. return 0;
  61. }
  62. DEFINE_LSM(LANDLOCK_NAME) = {
  63. .name = LANDLOCK_NAME,
  64. .init = landlock_init,
  65. .blobs = &landlock_blob_sizes,
  66. };