Skip to contentSkip to conversation

crypto: hmac - fix memory leak in hmac_init_tfm()

PATCH In review Eric Biggers 2 participants 2 messages May 22, 2019 – May 30, 2019 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: hmac - fix memory leak in hmac_init_tfm()

From: Eric Biggers <[email protected]>

When I added the sanity check of 'descsize', I missed that the child hash tfm needs to be freed if the sanity check fails. Of course this should never happen, hence the use of WARN_ON(), but it should be fixed.

Fixes e1354400b25d ("crypto: hash - fix incorrect HASH_MAX_DESCSIZE")
---
 crypto/hmac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/hmac.c +3 -1
index 241b1868c1d01..ac8c611ee33e4 100644
@@ -157,8 +157,10 @@ static int hmac_init_tfm(struct crypto_tfm *tfm)
 
 	parent->descsize = sizeof(struct shash_desc) +
 			   crypto_shash_descsize(hash);
-	if (WARN_ON(parent->descsize > HASH_MAX_DESCSIZE))
+	if (WARN_ON(parent->descsize > HASH_MAX_DESCSIZE)) {
+		crypto_free_shash(hash);
 		return -EINVAL;
+	}
 
 	ctx->hash = hash;
 	return 0;
Signature · 1 line
2.22.0.rc1.257.g3120a18244-goog
maintainer
#1 lore raw
Quoted 11 lines · Eric Biggers

From: Eric Biggers <[email protected]>

When I added the sanity check of 'descsize', I missed that the child hash tfm needs to be freed if the sanity check fails. Of course this should never happen, hence the use of WARN_ON(), but it should be fixed.

Fixes e1354400b25d ("crypto: hash - fix incorrect HASH_MAX_DESCSIZE")
---
 crypto/hmac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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