blob: 7b1d8caee669292b5f039c5ab1047fddcf09966e [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Neil Hormanccb778e2008-08-05 14:13:08 +08002/*
3 * FIPS 200 support.
4 *
5 * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
Neil Hormanccb778e2008-08-05 14:13:08 +08006 */
7
Herbert Xu76450f92015-04-22 13:25:54 +08008#include <linux/export.h>
9#include <linux/fips.h>
10#include <linux/init.h>
Herbert Xu94072cb2015-04-22 13:25:56 +080011#include <linux/module.h>
Herbert Xu76450f92015-04-22 13:25:54 +080012#include <linux/kernel.h>
Herbert Xu94072cb2015-04-22 13:25:56 +080013#include <linux/sysctl.h>
Gilad Ben-Yossef95523892019-07-02 14:39:20 +030014#include <linux/notifier.h>
Neil Hormanccb778e2008-08-05 14:13:08 +080015
16int fips_enabled;
17EXPORT_SYMBOL_GPL(fips_enabled);
18
Gilad Ben-Yossef95523892019-07-02 14:39:20 +030019ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
20EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
21
Neil Hormanccb778e2008-08-05 14:13:08 +080022/* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
23static int fips_enable(char *str)
24{
25 fips_enabled = !!simple_strtol(str, NULL, 0);
26 printk(KERN_INFO "fips mode: %s\n",
27 fips_enabled ? "enabled" : "disabled");
28 return 1;
29}
30
31__setup("fips=", fips_enable);
Herbert Xu94072cb2015-04-22 13:25:56 +080032
33static struct ctl_table crypto_sysctl_table[] = {
34 {
35 .procname = "fips_enabled",
36 .data = &fips_enabled,
37 .maxlen = sizeof(int),
38 .mode = 0444,
39 .proc_handler = proc_dointvec
40 },
41 {}
42};
43
44static struct ctl_table crypto_dir_table[] = {
45 {
46 .procname = "crypto",
47 .mode = 0555,
48 .child = crypto_sysctl_table
49 },
50 {}
51};
52
53static struct ctl_table_header *crypto_sysctls;
54
55static void crypto_proc_fips_init(void)
56{
57 crypto_sysctls = register_sysctl_table(crypto_dir_table);
58}
59
60static void crypto_proc_fips_exit(void)
61{
62 unregister_sysctl_table(crypto_sysctls);
63}
64
Gilad Ben-Yossef95523892019-07-02 14:39:20 +030065void fips_fail_notify(void)
66{
67 if (fips_enabled)
68 atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
69}
70EXPORT_SYMBOL_GPL(fips_fail_notify);
71
Herbert Xu94072cb2015-04-22 13:25:56 +080072static int __init fips_init(void)
73{
74 crypto_proc_fips_init();
75 return 0;
76}
77
78static void __exit fips_exit(void)
79{
80 crypto_proc_fips_exit();
81}
82
Eric Biggersc4741b22019-04-11 21:57:42 -070083subsys_initcall(fips_init);
Herbert Xu94072cb2015-04-22 13:25:56 +080084module_exit(fips_exit);