aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-04-15 23:07:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-15 23:26:16 -0400
commit34c9a0ffc75ad25b6a60f61e27c4a4b1189b8085 (patch)
tree293687562728755c0cd9186bfa8f9137a6b1cc92 /crypto
parenteea3a00264cf243a28e4331566ce67b86059339d (diff)
crypto: fix broken crypto_register_instance() module handling
Commit 9c521a200bc3 ("crypto: api - remove instance when test failed") tried to grab a module reference count before the module was even set. Worse, it then goes on to free the module reference count after it is set so you quickly end up with a negative module reference count which prevents people from using any instances belonging to that module. This patch moves the module initialisation before the reference count. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/algapi.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 2d0a1c64ce39..d2627a3d4ed8 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -525,12 +525,12 @@ int crypto_register_instance(struct crypto_template *tmpl,
525 if (err) 525 if (err)
526 return err; 526 return err;
527 527
528 if (unlikely(!crypto_mod_get(&inst->alg)))
529 return -EAGAIN;
530
531 inst->alg.cra_module = tmpl->module; 528 inst->alg.cra_module = tmpl->module;
532 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; 529 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
533 530
531 if (unlikely(!crypto_mod_get(&inst->alg)))
532 return -EAGAIN;
533
534 down_write(&crypto_alg_sem); 534 down_write(&crypto_alg_sem);
535 535
536 larval = __crypto_register_alg(&inst->alg); 536 larval = __crypto_register_alg(&inst->alg);