Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee34e264 authored by Tudor-Dan Ambarus's avatar Tudor-Dan Ambarus Committed by Herbert Xu
Browse files

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: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7380c56d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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;