Skip to content

Commit

Permalink
crypto: hmac - fix memory leak in hmac_init_tfm()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Biggers authored and Herbert Xu committed May 30, 2019
1 parent 9c5b34c commit 7829a0c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crypto/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7829a0c

Please sign in to comment.