Skip to content

Commit 34c9a0f

Browse files
herbertxtorvalds
authored andcommitted
crypto: fix broken crypto_register_instance() module handling
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]>
1 parent eea3a00 commit 34c9a0f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

crypto/algapi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,12 @@ int crypto_register_instance(struct crypto_template *tmpl,
525525
if (err)
526526
return err;
527527

528-
if (unlikely(!crypto_mod_get(&inst->alg)))
529-
return -EAGAIN;
530-
531528
inst->alg.cra_module = tmpl->module;
532529
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
533530

531+
if (unlikely(!crypto_mod_get(&inst->alg)))
532+
return -EAGAIN;
533+
534534
down_write(&crypto_alg_sem);
535535

536536
larval = __crypto_register_alg(&inst->alg);

0 commit comments

Comments
 (0)