Commit 9552389c authored by Gilad Ben-Yossef's avatar Gilad Ben-Yossef Committed by Herbert Xu

crypto: fips - add FIPS test failure notification chain

Crypto test failures in FIPS mode cause an immediate panic, but
on some system the cryptographic boundary extends beyond just
the Linux controlled domain.

Add a simple atomic notification chain to allow interested parties
to register to receive notification prior to us kicking the bucket.
Signed-off-by: default avatarGilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 76a95bd8
...@@ -11,10 +11,14 @@ ...@@ -11,10 +11,14 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/sysctl.h> #include <linux/sysctl.h>
#include <linux/notifier.h>
int fips_enabled; int fips_enabled;
EXPORT_SYMBOL_GPL(fips_enabled); EXPORT_SYMBOL_GPL(fips_enabled);
ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
/* Process kernel command-line parameter at boot time. fips=0 or fips=1 */ /* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
static int fips_enable(char *str) static int fips_enable(char *str)
{ {
...@@ -58,6 +62,13 @@ static void crypto_proc_fips_exit(void) ...@@ -58,6 +62,13 @@ static void crypto_proc_fips_exit(void)
unregister_sysctl_table(crypto_sysctls); unregister_sysctl_table(crypto_sysctls);
} }
void fips_fail_notify(void)
{
if (fips_enabled)
atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
}
EXPORT_SYMBOL_GPL(fips_fail_notify);
static int __init fips_init(void) static int __init fips_init(void)
{ {
crypto_proc_fips_init(); crypto_proc_fips_init();
......
...@@ -5240,9 +5240,11 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask) ...@@ -5240,9 +5240,11 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
type, mask); type, mask);
test_done: test_done:
if (rc && (fips_enabled || panic_on_fail)) if (rc && (fips_enabled || panic_on_fail)) {
fips_fail_notify();
panic("alg: self-tests for %s (%s) failed in %s mode!\n", panic("alg: self-tests for %s (%s) failed in %s mode!\n",
driver, alg, fips_enabled ? "fips" : "panic_on_fail"); driver, alg, fips_enabled ? "fips" : "panic_on_fail");
}
if (fips_enabled && !rc) if (fips_enabled && !rc)
pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
......
...@@ -4,8 +4,15 @@ ...@@ -4,8 +4,15 @@
#ifdef CONFIG_CRYPTO_FIPS #ifdef CONFIG_CRYPTO_FIPS
extern int fips_enabled; extern int fips_enabled;
extern struct atomic_notifier_head fips_fail_notif_chain;
void fips_fail_notify(void);
#else #else
#define fips_enabled 0 #define fips_enabled 0
static inline void fips_fail_notify(void) {}
#endif #endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment