summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorTudor-Dan Ambarus <tudor.ambarus@microchip.com>2017-05-25 10:18:07 +0300
committerHerbert Xu <herbert@gondor.apana.org.au>2017-06-10 12:04:26 +0800
commitee34e2644a78e2561742bea8c4bdcf83cabf90a7 (patch)
treeeb077fddef51f7e0abd4a9fba05ca523cff91b49 /crypto
parent7380c56d2fcaa882a0809aad075c3f9fdc3b3c50 (diff)
downloadlinux-stable-ee34e2644a78e2561742bea8c4bdcf83cabf90a7.tar.gz
linux-stable-ee34e2644a78e2561742bea8c4bdcf83cabf90a7.tar.bz2
linux-stable-ee34e2644a78e2561742bea8c4bdcf83cabf90a7.zip
crypto: dh - fix memleak in setkey
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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/dh.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/crypto/dh.c b/crypto/dh.c
index 7cec04985b9d..e151f12775ca 100644
--- a/crypto/dh.c
+++ b/crypto/dh.c
@@ -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;