From: Tudor-Dan Ambarus Date: Thu, 25 May 2017 07:18:07 +0000 (+0300) Subject: crypto: dh - fix memleak in setkey X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ee34e2644a78e2561742bea8c4bdcf83cabf90a7;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 Signed-off-by: Herbert Xu --- 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, ¶ms) < 0) return -EINVAL;