Skip to contentSkip to conversation

crypto: adiantum - fix leaking reference to hash algorithm

PATCH In review Eric Biggers 2 participants 2 messages Dec 10, 2018 – Dec 13, 2018 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: adiantum - fix leaking reference to hash algorithm

From: Eric Biggers <[email protected]>

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 059c2a4d8e16 ("crypto: adiantum - add Adiantum support")
---
 crypto/adiantum.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
crypto/adiantum.c +5 -4
index e62e34f5e389b..6651e713c45d6 100644
@@ -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,
@@ -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:
Signature · 1 line
2.20.0.rc2.403.gdbc3b29805-goog
maintainer
#1 lore raw
Quoted 8 lines · Eric Biggers

From: Eric Biggers <[email protected]>

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 059c2a4d8e16 ("crypto: adiantum - add Adiantum support")

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt