crypto: hmac - fix memory leak in hmac_init_tfm()
authorEric Biggers <ebiggers@google.com>
Wed, 22 May 2019 19:42:29 +0000 (12:42 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 30 May 2019 07:25:57 +0000 (15:25 +0800)
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")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/hmac.c

index 241b186..ac8c611 100644 (file)
@@ -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;