]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
crypto: dh - fix memleak in setkey
authorTudor-Dan Ambarus <tudor.ambarus@microchip.com>
Thu, 25 May 2017 07:18:07 +0000 (10:18 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 10 Jun 2017 04:04:26 +0000 (12:04 +0800)
setkey can be called multiple times during the existence
of the transformation object. In case of multiple setkey calls,
the old key was not freed and we leaked memory.
Free the old MPI key if any.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/dh.c

index 7cec04985b9d1eb1a608477b18481142284563b1..e151f12775ca22d54990b6d1ec1512fb35db5e33 100644 (file)
@@ -85,6 +85,9 @@ static int dh_set_secret(struct crypto_kpp *tfm, const void *buf,
        struct dh_ctx *ctx = dh_get_ctx(tfm);
        struct dh params;
 
+       /* Free the old MPI key if any */
+       dh_free_ctx(ctx);
+
        if (crypto_dh_decode_key(buf, len, &params) < 0)
                return -EINVAL;