Adding a patch for CVE-2022-0778 in `openssl`. (#2518)
This commit is contained in:
Родитель
8b05fc7c3c
Коммит
b7a512a0e8
|
@ -0,0 +1,176 @@
|
|||
From 72082ae738bbfdc552a0af55320cdc3c6fe16e1a Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Mon, 28 Feb 2022 18:26:21 +0100
|
||||
Subject: [PATCH 1/3] Fix possible infinite loop in BN_mod_sqrt()
|
||||
|
||||
The calculation in some cases does not finish for non-prime p.
|
||||
|
||||
This fixes CVE-2022-0778.
|
||||
|
||||
Based on patch by David Benjamin <davidben@google.com>.
|
||||
---
|
||||
crypto/bn/bn_sqrt.c | 30 ++++++++++++++++++------------
|
||||
1 file changed, 18 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/crypto/bn/bn_sqrt.c b/crypto/bn/bn_sqrt.c
|
||||
index 1723d5ded5a8..53b0f559855c 100644
|
||||
--- a/crypto/bn/bn_sqrt.c
|
||||
+++ b/crypto/bn/bn_sqrt.c
|
||||
@@ -14,7 +14,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
/*
|
||||
* Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks
|
||||
* algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number
|
||||
- * Theory", algorithm 1.5.1). 'p' must be prime!
|
||||
+ * Theory", algorithm 1.5.1). 'p' must be prime, otherwise an error or
|
||||
+ * an incorrect "result" will be returned.
|
||||
*/
|
||||
{
|
||||
BIGNUM *ret = in;
|
||||
@@ -301,18 +302,23 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
goto vrfy;
|
||||
}
|
||||
|
||||
- /* find smallest i such that b^(2^i) = 1 */
|
||||
- i = 1;
|
||||
- if (!BN_mod_sqr(t, b, p, ctx))
|
||||
- goto end;
|
||||
- while (!BN_is_one(t)) {
|
||||
- i++;
|
||||
- if (i == e) {
|
||||
- BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
|
||||
- goto end;
|
||||
+ /* Find the smallest i, 0 < i < e, such that b^(2^i) = 1. */
|
||||
+ for (i = 1; i < e; i++) {
|
||||
+ if (i == 1) {
|
||||
+ if (!BN_mod_sqr(t, b, p, ctx))
|
||||
+ goto end;
|
||||
+
|
||||
+ } else {
|
||||
+ if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
+ goto end;
|
||||
}
|
||||
- if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
- goto end;
|
||||
+ if (BN_is_one(t))
|
||||
+ break;
|
||||
+ }
|
||||
+ /* If not found, a is not a square or p is not prime. */
|
||||
+ if (i >= e) {
|
||||
+ BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
|
||||
+ goto end;
|
||||
}
|
||||
|
||||
/* t := y^2^(e - i - 1) */
|
||||
|
||||
From 6401ea8885e6004675bcf981aaad270f64180c1b Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Mon, 28 Feb 2022 18:26:30 +0100
|
||||
Subject: [PATCH 2/3] Add documentation of BN_mod_sqrt()
|
||||
|
||||
---
|
||||
doc/man3/BN_add.pod | 15 +++++++++++++--
|
||||
1 file changed, 13 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/doc/man3/BN_add.pod b/doc/man3/BN_add.pod
|
||||
index dccd4790ede7..1f5e37a4d183 100644
|
||||
--- a/doc/man3/BN_add.pod
|
||||
+++ b/doc/man3/BN_add.pod
|
||||
@@ -3,7 +3,7 @@
|
||||
=head1 NAME
|
||||
|
||||
BN_add, BN_sub, BN_mul, BN_sqr, BN_div, BN_mod, BN_nnmod, BN_mod_add,
|
||||
-BN_mod_sub, BN_mod_mul, BN_mod_sqr, BN_exp, BN_mod_exp, BN_gcd -
|
||||
+BN_mod_sub, BN_mod_mul, BN_mod_sqr, BN_mod_sqrt, BN_exp, BN_mod_exp, BN_gcd -
|
||||
arithmetic operations on BIGNUMs
|
||||
|
||||
=head1 SYNOPSIS
|
||||
@@ -36,6 +36,8 @@ arithmetic operations on BIGNUMs
|
||||
|
||||
int BN_mod_sqr(BIGNUM *r, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
|
||||
|
||||
+ BIGNUM *BN_mod_sqrt(BIGNUM *in, BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
+
|
||||
int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
|
||||
|
||||
int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
|
||||
@@ -87,6 +89,12 @@ L<BN_mod_mul_reciprocal(3)>.
|
||||
BN_mod_sqr() takes the square of I<a> modulo B<m> and places the
|
||||
result in I<r>.
|
||||
|
||||
+BN_mod_sqrt() returns the modular square root of I<a> such that
|
||||
+C<in^2 = a (mod p)>. The modulus I<p> must be a
|
||||
+prime, otherwise an error or an incorrect "result" will be returned.
|
||||
+The result is stored into I<in> which can be NULL. The result will be
|
||||
+newly allocated in that case.
|
||||
+
|
||||
BN_exp() raises I<a> to the I<p>-th power and places the result in I<r>
|
||||
(C<r=a^p>). This function is faster than repeated applications of
|
||||
BN_mul().
|
||||
@@ -108,7 +116,10 @@ the arguments.
|
||||
|
||||
=head1 RETURN VALUES
|
||||
|
||||
-For all functions, 1 is returned for success, 0 on error. The return
|
||||
+The BN_mod_sqrt() returns the result (possibly incorrect if I<p> is
|
||||
+not a prime), or NULL.
|
||||
+
|
||||
+For all remaining functions, 1 is returned for success, 0 on error. The return
|
||||
value should always be checked (e.g., C<if (!BN_add(r,a,b)) goto err;>).
|
||||
The error codes can be obtained by L<ERR_get_error(3)>.
|
||||
|
||||
From 48abbd97dc8834240eacb46f64b1fae43bfe9554 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Mon, 28 Feb 2022 18:26:35 +0100
|
||||
Subject: [PATCH 3/3] Add a negative testcase for BN_mod_sqrt
|
||||
|
||||
---
|
||||
test/bntest.c | 11 ++++++++++-
|
||||
test/recipes/10-test_bn_data/bnmod.txt | 12 ++++++++++++
|
||||
2 files changed, 22 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/bntest.c b/test/bntest.c
|
||||
index 390dd800733e..1cab660bcafb 100644
|
||||
--- a/test/bntest.c
|
||||
+++ b/test/bntest.c
|
||||
@@ -1729,8 +1729,17 @@ static int file_modsqrt(STANZA *s)
|
||||
|| !TEST_ptr(ret2 = BN_new()))
|
||||
goto err;
|
||||
|
||||
+ if (BN_is_negative(mod_sqrt)) {
|
||||
+ /* A negative testcase */
|
||||
+ if (!TEST_ptr_null(BN_mod_sqrt(ret, a, p, ctx)))
|
||||
+ goto err;
|
||||
+
|
||||
+ st = 1;
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
/* There are two possible answers. */
|
||||
- if (!TEST_true(BN_mod_sqrt(ret, a, p, ctx))
|
||||
+ if (!TEST_ptr(BN_mod_sqrt(ret, a, p, ctx))
|
||||
|| !TEST_true(BN_sub(ret2, p, ret)))
|
||||
goto err;
|
||||
|
||||
diff --git a/test/recipes/10-test_bn_data/bnmod.txt b/test/recipes/10-test_bn_data/bnmod.txt
|
||||
index 5ea4d031f271..e28cc6bfb02e 100644
|
||||
--- a/test/recipes/10-test_bn_data/bnmod.txt
|
||||
+++ b/test/recipes/10-test_bn_data/bnmod.txt
|
||||
@@ -2799,3 +2799,15 @@ P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
|
||||
ModSqrt = a1d52989f12f204d3d2167d9b1e6c8a6174c0c786a979a5952383b7b8bd186
|
||||
A = 2eee37cf06228a387788188e650bc6d8a2ff402931443f69156a29155eca07dcb45f3aac238d92943c0c25c896098716baa433f25bd696a142f5a69d5d937e81
|
||||
P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
|
||||
+
|
||||
+# Negative testcases for BN_mod_sqrt()
|
||||
+
|
||||
+# This one triggers an infinite loop with unfixed implementation
|
||||
+# It should just fail.
|
||||
+ModSqrt = -1
|
||||
+A = 20a7ee
|
||||
+P = 460201
|
||||
+
|
||||
+ModSqrt = -1
|
||||
+A = 65bebdb00a96fc814ec44b81f98b59fba3c30203928fa5214c51e0a97091645280c947b005847f239758482b9bfc45b066fde340d1fe32fc9c1bf02e1b2d0ed
|
||||
+P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
|
||||
--
|
||||
2.25.1
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
Summary: Utilities from the general purpose cryptography library with TLS implementation
|
||||
Name: openssl
|
||||
Version: 1.1.1k
|
||||
Release: 11%{?dist}
|
||||
Release: 12%{?dist}
|
||||
License: OpenSSL
|
||||
Vendor: Microsoft Corporation
|
||||
Distribution: Mariner
|
||||
|
@ -44,6 +44,7 @@ Patch21: openssl-1.1.1-drbg-seed.patch
|
|||
Patch22: openssl-1.1.1-fips-SymCrypt.patch
|
||||
Patch23: CVE-2021-3711.patch
|
||||
Patch24: CVE-2021-3712.patch
|
||||
Patch25: CVE-2022-0778.patch
|
||||
BuildRequires: perl-Test-Warnings
|
||||
BuildRequires: perl-Text-Template
|
||||
BuildRequires: perl(FindBin)
|
||||
|
@ -141,6 +142,7 @@ cp %{SOURCE4} test/
|
|||
# %patch22 -p1
|
||||
%patch23 -p1
|
||||
%patch24 -p1
|
||||
%patch25 -p1
|
||||
|
||||
%build
|
||||
# Add -Wa,--noexecstack here so that libcrypto's assembler modules will be
|
||||
|
@ -330,6 +332,9 @@ rm -f %{buildroot}%{_sysconfdir}/pki/tls/ct_log_list.cnf.dist
|
|||
%postun libs -p /sbin/ldconfig
|
||||
|
||||
%changelog
|
||||
* Thu Mar 10 2022 Pawel Winogrodzki <pawelwi@microsoft.com> - 1.1.1k-12
|
||||
- Adding a patch for CVE-2022-0778.
|
||||
|
||||
* Thu Mar 10 2022 Max Brodeur-Urbas <maxbr@microsoft.com> - 1.1.1k-11
|
||||
- dmihai@microsoft.com, 1.1.1k-6: Enable support for TLS 1 and TLS 1.1
|
||||
- niontive@microsoft.com, 1.1.1k-7: Patch CVE-2021-3711 and CVE-2021-3712.
|
||||
|
|
|
@ -164,12 +164,12 @@ texinfo-6.8-1.cm2.aarch64.rpm
|
|||
gtk-doc-1.33.2-1.cm2.noarch.rpm
|
||||
autoconf-2.71-3.cm2.noarch.rpm
|
||||
automake-1.16.5-1.cm2.noarch.rpm
|
||||
openssl-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-debuginfo-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-devel-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-libs-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-perl-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-static-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-debuginfo-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-devel-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-libs-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-perl-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-static-1.1.1k-12.cm2.aarch64.rpm
|
||||
libcap-2.26-2.cm2.aarch64.rpm
|
||||
libcap-devel-2.26-2.cm2.aarch64.rpm
|
||||
debugedit-5.0-1.cm2.aarch64.rpm
|
||||
|
|
|
@ -164,12 +164,12 @@ texinfo-6.8-1.cm2.x86_64.rpm
|
|||
gtk-doc-1.33.2-1.cm2.noarch.rpm
|
||||
autoconf-2.71-3.cm2.noarch.rpm
|
||||
automake-1.16.5-1.cm2.noarch.rpm
|
||||
openssl-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-devel-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-libs-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-perl-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-static-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-debuginfo-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-devel-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-libs-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-perl-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-static-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-debuginfo-1.1.1k-12.cm2.x86_64.rpm
|
||||
libcap-2.26-2.cm2.x86_64.rpm
|
||||
libcap-devel-2.26-2.cm2.x86_64.rpm
|
||||
debugedit-5.0-1.cm2.x86_64.rpm
|
||||
|
|
|
@ -255,12 +255,12 @@ nspr-4.30-1.cm2.aarch64.rpm
|
|||
nspr-debuginfo-4.30-1.cm2.aarch64.rpm
|
||||
nspr-devel-4.30-1.cm2.aarch64.rpm
|
||||
ntsysv-1.20-2.cm2.aarch64.rpm
|
||||
openssl-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-debuginfo-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-devel-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-libs-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-perl-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-static-1.1.1k-11.cm2.aarch64.rpm
|
||||
openssl-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-debuginfo-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-devel-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-libs-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-perl-1.1.1k-12.cm2.aarch64.rpm
|
||||
openssl-static-1.1.1k-12.cm2.aarch64.rpm
|
||||
p11-kit-0.24.1-1.cm2.aarch64.rpm
|
||||
p11-kit-debuginfo-0.24.1-1.cm2.aarch64.rpm
|
||||
p11-kit-devel-0.24.1-1.cm2.aarch64.rpm
|
||||
|
|
|
@ -255,12 +255,12 @@ nspr-4.30-1.cm2.x86_64.rpm
|
|||
nspr-debuginfo-4.30-1.cm2.x86_64.rpm
|
||||
nspr-devel-4.30-1.cm2.x86_64.rpm
|
||||
ntsysv-1.20-2.cm2.x86_64.rpm
|
||||
openssl-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-debuginfo-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-devel-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-libs-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-perl-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-static-1.1.1k-11.cm2.x86_64.rpm
|
||||
openssl-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-debuginfo-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-devel-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-libs-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-perl-1.1.1k-12.cm2.x86_64.rpm
|
||||
openssl-static-1.1.1k-12.cm2.x86_64.rpm
|
||||
p11-kit-0.24.1-1.cm2.x86_64.rpm
|
||||
p11-kit-debuginfo-0.24.1-1.cm2.x86_64.rpm
|
||||
p11-kit-devel-0.24.1-1.cm2.x86_64.rpm
|
||||
|
|
Загрузка…
Ссылка в новой задаче