Skip to content

Commit

Permalink
crypto: fix broken crypto_register_instance() module handling
Browse files Browse the repository at this point in the history
Commit 9c521a2 ("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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
herbertx authored and torvalds committed Apr 16, 2015
1 parent eea3a00 commit 34c9a0f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crypto/algapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,12 @@ int crypto_register_instance(struct crypto_template *tmpl,
if (err)
return err;

if (unlikely(!crypto_mod_get(&inst->alg)))
return -EAGAIN;

inst->alg.cra_module = tmpl->module;
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;

if (unlikely(!crypto_mod_get(&inst->alg)))
return -EAGAIN;

down_write(&crypto_alg_sem);

larval = __crypto_register_alg(&inst->alg);
Expand Down

0 comments on commit 34c9a0f

Please sign in to comment.