fips.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. int fips_enabled;
  15. EXPORT_SYMBOL_GPL(fips_enabled);
  16. ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
  17. EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
  18. /* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
  19. static int fips_enable(char *str)
  20. {
  21. fips_enabled = !!simple_strtol(str, NULL, 0);
  22. printk(KERN_INFO "fips mode: %s\n",
  23. fips_enabled ? "enabled" : "disabled");
  24. return 1;
  25. }
  26. __setup("fips=", fips_enable);
  27. static struct ctl_table crypto_sysctl_table[] = {
  28. {
  29. .procname = "fips_enabled",
  30. .data = &fips_enabled,
  31. .maxlen = sizeof(int),
  32. .mode = 0444,
  33. .proc_handler = proc_dointvec
  34. },
  35. {}
  36. };
  37. static struct ctl_table crypto_dir_table[] = {
  38. {
  39. .procname = "crypto",
  40. .mode = 0555,
  41. .child = crypto_sysctl_table
  42. },
  43. {}
  44. };
  45. static struct ctl_table_header *crypto_sysctls;
  46. static void crypto_proc_fips_init(void)
  47. {
  48. crypto_sysctls = register_sysctl_table(crypto_dir_table);
  49. }
  50. static void crypto_proc_fips_exit(void)
  51. {
  52. unregister_sysctl_table(crypto_sysctls);
  53. }
  54. void fips_fail_notify(void)
  55. {
  56. if (fips_enabled)
  57. atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
  58. }
  59. EXPORT_SYMBOL_GPL(fips_fail_notify);
  60. static int __init fips_init(void)
  61. {
  62. crypto_proc_fips_init();
  63. return 0;
  64. }
  65. static void __exit fips_exit(void)
  66. {
  67. crypto_proc_fips_exit();
  68. }
  69. subsys_initcall(fips_init);
  70. module_exit(fips_exit);