Skip to content

Commit 7829a0c

Browse files
ebiggersherbertx
authored andcommitted
crypto: hmac - fix memory leak in hmac_init_tfm()
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: e135440 ("crypto: hash - fix incorrect HASH_MAX_DESCSIZE") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9c5b34c commit 7829a0c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎crypto/hmac.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ static int hmac_init_tfm(struct crypto_tfm *tfm)
157157

158158
parent->descsize = sizeof(struct shash_desc) +
159159
crypto_shash_descsize(hash);
160-
if (WARN_ON(parent->descsize > HASH_MAX_DESCSIZE))
160+
if (WARN_ON(parent->descsize > HASH_MAX_DESCSIZE)) {
161+
crypto_free_shash(hash);
161162
return -EINVAL;
163+
}
162164

163165
ctx->hash = hash;
164166
return 0;

0 commit comments

Comments
 (0)