crypto: sm2 - fix a memory leak in sm2
authorHongbo Li <herberthbli@tencent.com>
Fri, 4 Jun 2021 06:30:35 +0000 (14:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Jul 2021 14:56:06 +0000 (16:56 +0200)
commitcd909ebb7315f0a30dd2f5effe526b724cb94453
tree4335330facbf6c1942c521eeb1f0aafab8d0d021
parentd598b8b77b17cf1f62659c62998e05992eb998d4
crypto: sm2 - fix a memory leak in sm2

[ Upstream commit 5cd259ca5d466f65ffd21e2e2fa00fb648a8c555 ]

SM2 module alloc ec->Q in sm2_set_pub_key(), when doing alg test in
test_akcipher_one(), it will set public key for every test vector,
and don't free ec->Q. This will cause a memory leak.

This patch alloc ec->Q in sm2_ec_ctx_init().

Fixes: ea7ecb66440b ("crypto: sm2 - introduce OSCCA SM2 asymmetric cipher algorithm")
Signed-off-by: Hongbo Li <herberthbli@tencent.com>
Reviewed-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
crypto/sm2.c