fips.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * FIPS 200 support.
  4. *
  5. * Copyright (c) 2008 Neil Horman <[email protected]>
  6. */
  7. #include <linux/export.h>
  8. #include <linux/fips.h>
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/sysctl.h>
  13. #include <linux/notifier.h>
  14. #include <generated/utsrelease.h>
  15. int fips_enabled;
  16. EXPORT_SYMBOL_GPL(fips_enabled);
  17. ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
  18. EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
  19. /* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
  20. static int fips_enable(char *str)
  21. {
  22. fips_enabled = !!simple_strtol(str, NULL, 0);
  23. printk(KERN_INFO "fips mode: %s\n",
  24. fips_enabled ? "enabled" : "disabled");
  25. return 1;
  26. }
  27. __setup("fips=", fips_enable);
  28. #define FIPS_MODULE_NAME CONFIG_CRYPTO_FIPS_NAME
  29. #ifdef CONFIG_CRYPTO_FIPS_CUSTOM_VERSION
  30. #define FIPS_MODULE_VERSION CONFIG_CRYPTO_FIPS_VERSION
  31. #else
  32. #define FIPS_MODULE_VERSION UTS_RELEASE
  33. #endif
  34. static char fips_name[] = FIPS_MODULE_NAME;
  35. static char fips_version[] = FIPS_MODULE_VERSION;
  36. static struct ctl_table crypto_sysctl_table[] = {
  37. {
  38. .procname = "fips_enabled",
  39. .data = &fips_enabled,
  40. .maxlen = sizeof(int),
  41. .mode = 0444,
  42. .proc_handler = proc_dointvec
  43. },
  44. {
  45. .procname = "fips_name",
  46. .data = &fips_name,
  47. .maxlen = 64,
  48. .mode = 0444,
  49. .proc_handler = proc_dostring
  50. },
  51. {
  52. .procname = "fips_version",
  53. .data = &fips_version,
  54. .maxlen = 64,
  55. .mode = 0444,
  56. .proc_handler = proc_dostring
  57. },
  58. {}
  59. };
  60. static struct ctl_table crypto_dir_table[] = {
  61. {
  62. .procname = "crypto",
  63. .mode = 0555,
  64. .child = crypto_sysctl_table
  65. },
  66. {}
  67. };
  68. static struct ctl_table_header *crypto_sysctls;
  69. static void crypto_proc_fips_init(void)
  70. {
  71. crypto_sysctls = register_sysctl_table(crypto_dir_table);
  72. }
  73. static void crypto_proc_fips_exit(void)
  74. {
  75. unregister_sysctl_table(crypto_sysctls);
  76. }
  77. void fips_fail_notify(void)
  78. {
  79. if (fips_enabled)
  80. atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
  81. }
  82. EXPORT_SYMBOL_GPL(fips_fail_notify);
  83. static int __init fips_init(void)
  84. {
  85. crypto_proc_fips_init();
  86. return 0;
  87. }
  88. static void __exit fips_exit(void)
  89. {
  90. crypto_proc_fips_exit();
  91. }
  92. subsys_initcall(fips_init);
  93. module_exit(fips_exit);