Skip to content

Commit 2115562

Browse files
uudiinherbertx
authored andcommitted
crypto: sm2 - Fix crash caused by uninitialized context
In sm2_compute_z_digest() function, the newly allocated structure mpi_ec_ctx is used, but forget to initialize it, which will cause a crash when performing subsequent operations. Fixes: e5221fa ("KEYS: asymmetric: Move sm2 code into x509_public_key") Cc: stable@vger.kernel.org # v6.5 Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 0bb80ec commit 2115562

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crypto/sm2.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,14 @@ int sm2_compute_z_digest(struct shash_desc *desc,
278278
if (!ec)
279279
return -ENOMEM;
280280

281-
err = __sm2_set_pub_key(ec, key, keylen);
281+
err = sm2_ec_ctx_init(ec);
282282
if (err)
283283
goto out_free_ec;
284284

285+
err = __sm2_set_pub_key(ec, key, keylen);
286+
if (err)
287+
goto out_deinit_ec;
288+
285289
bits_len = SM2_DEFAULT_USERID_LEN * 8;
286290
entl[0] = bits_len >> 8;
287291
entl[1] = bits_len & 0xff;

0 commit comments

Comments
 (0)