Skip to content

Commit

Permalink
crypto: adiantum - fix leaking reference to hash algorithm
Browse files Browse the repository at this point in the history
crypto_alg_mod_lookup() takes a reference to the hash algorithm but
crypto_init_shash_spawn() doesn't take ownership of it, hence the
reference needs to be dropped in adiantum_create().

Fixes: 059c2a4 ("crypto: adiantum - add Adiantum support")
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
ebiggers authored and herbertx committed Dec 13, 2018
1 parent 0ac6b8f commit 00c9fe3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crypto/adiantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,8 @@ static int adiantum_create(struct crypto_template *tmpl, struct rtattr **tb)
hash_alg = __crypto_shash_alg(_hash_alg);
err = crypto_init_shash_spawn(&ictx->hash_spawn, hash_alg,
skcipher_crypto_instance(inst));
if (err) {
crypto_mod_put(_hash_alg);
goto out_drop_blockcipher;
}
if (err)
goto out_put_hash;

/* Check the set of algorithms */
if (!adiantum_supported_algorithms(streamcipher_alg, blockcipher_alg,
Expand Down Expand Up @@ -624,10 +622,13 @@ static int adiantum_create(struct crypto_template *tmpl, struct rtattr **tb)
if (err)
goto out_drop_hash;

crypto_mod_put(_hash_alg);
return 0;

out_drop_hash:
crypto_drop_shash(&ictx->hash_spawn);
out_put_hash:
crypto_mod_put(_hash_alg);
out_drop_blockcipher:
crypto_drop_spawn(&ictx->blockcipher_spawn);
out_drop_streamcipher:
Expand Down

0 comments on commit 00c9fe3

Please sign in to comment.