fips.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * FIPS 200 support.
  4. *
  5. * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
  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. static struct ctl_table_header *crypto_sysctls;
  60. static void crypto_proc_fips_init(void)
  61. {
  62. crypto_sysctls = register_sysctl("crypto", crypto_sysctl_table);
  63. }
  64. static void crypto_proc_fips_exit(void)
  65. {
  66. unregister_sysctl_table(crypto_sysctls);
  67. }
  68. void fips_fail_notify(void)
  69. {
  70. if (fips_enabled)
  71. atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
  72. }
  73. EXPORT_SYMBOL_GPL(fips_fail_notify);
  74. static int __init fips_init(void)
  75. {
  76. crypto_proc_fips_init();
  77. return 0;
  78. }
  79. static void __exit fips_exit(void)
  80. {
  81. crypto_proc_fips_exit();
  82. }
  83. subsys_initcall(fips_init);
  84. module_exit(fips_exit);