]> git.ipfire.org Git - people/arne_f/kernel.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 24 Nov 2017 07:33:41 +0000 (08:33 +0100)
commit ee34e2644a78e2561742bea8c4bdcf83cabf90a7 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
crypto/dh.c

index 9d19360e71897d3971f117338c27eb151d8f3e25..df7698e4f740851f07a2ec8a0d55260cc88ef61e 100644 (file)
@@ -84,6 +84,9 @@ static int dh_set_secret(struct crypto_kpp *tfm, void *buf, unsigned int len)
        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;