init.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * fs-verity module initialization and logging
  4. *
  5. * Copyright 2019 Google LLC
  6. */
  7. #include "fsverity_private.h"
  8. #include <linux/ratelimit.h>
  9. #ifdef CONFIG_SYSCTL
  10. static struct ctl_table fsverity_sysctl_table[] = {
  11. #ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES
  12. {
  13. .procname = "require_signatures",
  14. .data = &fsverity_require_signatures,
  15. .maxlen = sizeof(int),
  16. .mode = 0644,
  17. .proc_handler = proc_dointvec_minmax,
  18. .extra1 = SYSCTL_ZERO,
  19. .extra2 = SYSCTL_ONE,
  20. },
  21. #endif
  22. };
  23. static void __init fsverity_init_sysctl(void)
  24. {
  25. register_sysctl_init("fs/verity", fsverity_sysctl_table);
  26. }
  27. #else /* CONFIG_SYSCTL */
  28. static inline void fsverity_init_sysctl(void)
  29. {
  30. }
  31. #endif /* !CONFIG_SYSCTL */
  32. void fsverity_msg(const struct inode *inode, const char *level,
  33. const char *fmt, ...)
  34. {
  35. static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
  36. DEFAULT_RATELIMIT_BURST);
  37. struct va_format vaf;
  38. va_list args;
  39. if (!__ratelimit(&rs))
  40. return;
  41. va_start(args, fmt);
  42. vaf.fmt = fmt;
  43. vaf.va = &args;
  44. if (inode)
  45. printk("%sfs-verity (%s, inode %lu): %pV\n",
  46. level, inode->i_sb->s_id, inode->i_ino, &vaf);
  47. else
  48. printk("%sfs-verity: %pV\n", level, &vaf);
  49. va_end(args);
  50. }
  51. static int __init fsverity_init(void)
  52. {
  53. fsverity_check_hash_algs();
  54. fsverity_init_info_cache();
  55. fsverity_init_workqueue();
  56. fsverity_init_sysctl();
  57. fsverity_init_signature();
  58. fsverity_init_bpf();
  59. return 0;
  60. }
  61. late_initcall(fsverity_init)