init.c 1.5 KB

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