aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/algapi.c
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2015-04-09 06:09:55 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-04-10 09:39:38 -0400
commit9c521a200bc3c12bd724e48a75c57d5358f672be (patch)
tree5e052c77b18d3602a0a0aa56b2d544bf234bb3f3 /crypto/algapi.c
parente9b8e5beb7befe682f9fe90428ea534b01d66568 (diff)
crypto: api - remove instance when test failed
A cipher instance is added to the list of instances unconditionally regardless of whether the associated test failed. However, a failed test implies that during another lookup, the cipher instance will be added to the list again as it will not be found by the lookup code. That means that the list can be filled up with instances whose tests failed. Note: tests only fail in reality in FIPS mode when a cipher is not marked as fips_allowed=1. This can be seen with cmac(des3_ede) that does not have a fips_allowed=1. When allocating the cipher, the allocation fails with -ENOENT due to the missing fips_allowed=1 flag (which causes the testmgr to return EINVAL). Yet, the instance of cmac(des3_ede) is shown in /proc/crypto. Allocating the cipher again fails again, but a 2nd instance is listed in /proc/crypto. The patch simply de-registers the instance when the testing failed. Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 1462c68492ea..2d0a1c64ce39 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -523,7 +523,10 @@ int crypto_register_instance(struct crypto_template *tmpl,
523 523
524 err = crypto_check_alg(&inst->alg); 524 err = crypto_check_alg(&inst->alg);
525 if (err) 525 if (err)
526 goto err; 526 return err;
527
528 if (unlikely(!crypto_mod_get(&inst->alg)))
529 return -EAGAIN;
527 530
528 inst->alg.cra_module = tmpl->module; 531 inst->alg.cra_module = tmpl->module;
529 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; 532 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
@@ -545,9 +548,14 @@ unlock:
545 goto err; 548 goto err;
546 549
547 crypto_wait_for_test(larval); 550 crypto_wait_for_test(larval);
551
552 /* Remove instance if test failed */
553 if (!(inst->alg.cra_flags & CRYPTO_ALG_TESTED))
554 crypto_unregister_instance(inst);
548 err = 0; 555 err = 0;
549 556
550err: 557err:
558 crypto_mod_put(&inst->alg);
551 return err; 559 return err;
552} 560}
553EXPORT_SYMBOL_GPL(crypto_register_instance); 561EXPORT_SYMBOL_GPL(crypto_register_instance);