Check for 0 modulus in BN_RECP_CTX_set.
authorfullwaywang <fullwaywang@tencent.com>
Wed, 21 Jun 2023 07:00:06 +0000 (15:00 +0800)
committerPauli <pauli@openssl.org>
Sun, 25 Jun 2023 22:07:55 +0000 (08:07 +1000)
The function BN_RECP_CTX_set did not check whether arg d is zero,
in which case an early failure should be returned to the invoker.
This is a similar fix to the cognate defect of CVE-2015-1794.

Fixes #21111

CLA: trivial

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21255)

crypto/bn/bn_recp.c

index 462329ad255ee45b0de5bb7bfa4f83f843592b50..aa548d62eaef51a724c9806af7155f676b58a91a 100644 (file)
@@ -42,7 +42,7 @@ void BN_RECP_CTX_free(BN_RECP_CTX *recp)
 
 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
 {
-    if (!BN_copy(&(recp->N), d))
+    if (BN_is_zero(d) || !BN_copy(&(recp->N), d))
         return 0;
     BN_zero(&(recp->Nr));
     recp->num_bits = BN_num_bits(d);