...
 
Commits (7)
    https://gitcode.net/openharmony/third_party_openssl/-/commit/4377827ffae6060bc647ed1f76d5d3b637708db7 Fix DH_check() excessive time with over sized modulus 2023-07-31T16:48:26+08:00 Matt Caswell matt@openssl.org The DH_check() function checks numerous aspects of the key or parameters that have been supplied. Some of those checks use the supplied modulus value even if it is excessively large. There is already a maximum DH modulus size (10,000 bits) over which OpenSSL will not generate or derive keys. DH_check() will however still perform various tests for validity on such a large modulus. We introduce a new maximum (32,768) over which DH_check() will just fail. An application that calls DH_check() and supplies a key or parameters obtained from an untrusted source could be vulnerable to a Denial of Service attack. The function DH_check() is itself called by a number of other OpenSSL functions. An application calling any of those other functions may similarly be affected. The other functions affected by this are DH_check_ex() and EVP_PKEY_param_check(). CVE-2023-3446 Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:pauli@openssl.org" title="pauli@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:pauli@openssl.org" title="pauli@openssl.org">Paul Dale</a> &lt;<a href="mailto:pauli@openssl.org" title="pauli@openssl.org">pauli@openssl.org</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com">Tom Cosgrove</a> &lt;<a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com">tom.cosgrove@arm.com</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg2" style="text-decoration: none">N</a><a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de">Bernd Edlinger</a> &lt;<a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de">bernd.edlinger@hotmail.de</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:tomas@openssl.org" title="tomas@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg5" style="text-decoration: none">N</a><a href="mailto:tomas@openssl.org" title="tomas@openssl.org">Tomas Mraz</a> &lt;<a href="mailto:tomas@openssl.org" title="tomas@openssl.org">tomas@openssl.org</a>&gt;</span> (Merged from <a href="https://github.com/openssl/openssl/pull/21452" rel="nofollow noreferrer noopener" target="_blank">https://github.com/openssl/openssl/pull/21452</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg5" style="text-decoration: none">N</a><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">code4lala</a> &lt;<a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">fengziteng2@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/third_party_openssl/-/commit/998e0af2e618c8c066eb5b212c5105ec3504302f Add a test for CVE-2023-3446 2023-07-31T16:48:35+08:00 Matt Caswell matt@openssl.org Confirm that the only errors DH_check() finds with DH parameters with an excessively long modulus is that the modulus is too large. We should not be performing time consuming checks using that modulus. Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:pauli@openssl.org" title="pauli@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:pauli@openssl.org" title="pauli@openssl.org">Paul Dale</a> &lt;<a href="mailto:pauli@openssl.org" title="pauli@openssl.org">pauli@openssl.org</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg2" style="text-decoration: none">N</a><a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com">Tom Cosgrove</a> &lt;<a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com">tom.cosgrove@arm.com</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg2" style="text-decoration: none">N</a><a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de">Bernd Edlinger</a> &lt;<a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de">bernd.edlinger@hotmail.de</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:tomas@openssl.org" title="tomas@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg1" style="text-decoration: none">N</a><a href="mailto:tomas@openssl.org" title="tomas@openssl.org">Tomas Mraz</a> &lt;<a href="mailto:tomas@openssl.org" title="tomas@openssl.org">tomas@openssl.org</a>&gt;</span> (Merged from <a href="https://github.com/openssl/openssl/pull/21452" rel="nofollow noreferrer noopener" target="_blank">https://github.com/openssl/openssl/pull/21452</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg1" style="text-decoration: none">N</a><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">code4lala</a> &lt;<a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">fengziteng2@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/third_party_openssl/-/commit/96f1baaaa7b607ad4721b7ff9730c62dc6192552 Update CHANGES/NEWS for CVE-2023-3446 2023-07-31T16:49:31+08:00 Matt Caswell matt@openssl.org Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:pauli@openssl.org" title="pauli@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:pauli@openssl.org" title="pauli@openssl.org">Paul Dale</a> &lt;<a href="mailto:pauli@openssl.org" title="pauli@openssl.org">pauli@openssl.org</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com">Tom Cosgrove</a> &lt;<a href="mailto:tom.cosgrove@arm.com" title="tom.cosgrove@arm.com">tom.cosgrove@arm.com</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg2" style="text-decoration: none">N</a><a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de">Bernd Edlinger</a> &lt;<a href="mailto:bernd.edlinger@hotmail.de" title="bernd.edlinger@hotmail.de">bernd.edlinger@hotmail.de</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:tomas@openssl.org" title="tomas@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:tomas@openssl.org" title="tomas@openssl.org">Tomas Mraz</a> &lt;<a href="mailto:tomas@openssl.org" title="tomas@openssl.org">tomas@openssl.org</a>&gt;</span> (Merged from <a href="https://github.com/openssl/openssl/pull/21452" rel="nofollow noreferrer noopener" target="_blank">https://github.com/openssl/openssl/pull/21452</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">code4lala</a> &lt;<a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">fengziteng2@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/third_party_openssl/-/commit/58dcbf4a09d58df5cf19e39b96d3bebd08bc0116 !128 fix-CVE-2023-3446-for-OpenHarmony-3.0-LTS 2023-08-02T08:01:54+00:00 openharmony_ci 120357966@qq.com Merge pull request !128 from code4lala/fix-CVE-2023-3446-for-OpenHarmony-3.0-LTS https://gitcode.net/openharmony/third_party_openssl/-/commit/dea119810ce81d14abb50a0905ae97100366e737 DH_check(): Do not try checking q properties if it is obviously invalid 2023-08-07T15:06:54+08:00 Tomas Mraz tomas@openssl.org If |q| &gt;= |p| then the q value is obviously wrong as q is supposed to be a prime divisor of p-1. We check if p is overly large so this added test implies that q is not large either when performing subsequent tests using that q value. Otherwise if it is too large these additional checks of the q value such as the primality test can then trigger DoS by doing overly long computations. Fixes CVE-2023-3817 Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:pauli@openssl.org" title="pauli@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:pauli@openssl.org" title="pauli@openssl.org">Paul Dale</a> &lt;<a href="mailto:pauli@openssl.org" title="pauli@openssl.org">pauli@openssl.org</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:matt@openssl.org" title="matt@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:matt@openssl.org" title="matt@openssl.org">Matt Caswell</a> &lt;<a href="mailto:matt@openssl.org" title="matt@openssl.org">matt@openssl.org</a>&gt;</span> (Merged from <a href="https://github.com/openssl/openssl/pull/21551" rel="nofollow noreferrer noopener" target="_blank">https://github.com/openssl/openssl/pull/21551</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">code4lala</a> &lt;<a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">fengziteng2@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/third_party_openssl/-/commit/3501c55090a809dc20bc65e964b6b2d6a9b38d9d Add CHANGES/NEWS for CVE-2023-3817 2023-08-07T15:07:47+08:00 Tomas Mraz tomas@openssl.org Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:pauli@openssl.org" title="pauli@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:pauli@openssl.org" title="pauli@openssl.org">Paul Dale</a> &lt;<a href="mailto:pauli@openssl.org" title="pauli@openssl.org">pauli@openssl.org</a>&gt;</span> Reviewed-by: <span data-trailer="Reviewed-by:"><a href="mailto:matt@openssl.org" title="matt@openssl.org"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg4" style="text-decoration: none">N</a><a href="mailto:matt@openssl.org" title="matt@openssl.org">Matt Caswell</a> &lt;<a href="mailto:matt@openssl.org" title="matt@openssl.org">matt@openssl.org</a>&gt;</span> (Merged from <a href="https://github.com/openssl/openssl/pull/21551" rel="nofollow noreferrer noopener" target="_blank">https://github.com/openssl/openssl/pull/21551</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg1" style="text-decoration: none">N</a><a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">code4lala</a> &lt;<a href="mailto:fengziteng2@huawei.com" title="fengziteng2@huawei.com">fengziteng2@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/third_party_openssl/-/commit/882a3636330d75343de64512e6d07a2ec6adf8a7 !132 fix-CVE-2023-3817-for-OpenHarmony-3.0-LTS 2023-08-07T12:33:29+00:00 openharmony_ci 120357966@qq.com Merge pull request !132 from code4lala/fix-CVE-2023-3817-for-OpenHarmony-3.0-LTS
......@@ -6,6 +6,38 @@
For a full list of changes, see the git commit log; for example,
https://github.com/openssl/openssl/commits/ and pick the appropriate
release branch.
*) Fix excessive time spent checking DH q parameter value.
The function DH_check() performs various checks on DH parameters. After
fixing CVE-2023-3446 it was discovered that a large q parameter value can
also trigger an overly long computation during some of these checks.
A correct q value, if present, cannot be larger than the modulus p
parameter, thus it is unnecessary to perform these checks if q is larger
than p.
If DH_check() is called with such q parameter value,
DH_CHECK_INVALID_Q_VALUE return flag is set and the computationally
intensive checks are skipped.
(CVE-2023-3817)
[Tomáš Mráz]
*) Fix DH_check() excessive time with over sized modulus
The function DH_check() performs various checks on DH parameters. One of
those checks confirms that the modulus ("p" parameter) is not too large.
Trying to use a very large modulus is slow and OpenSSL will not normally use
a modulus which is over 10,000 bits in length.
However the DH_check() function checks numerous aspects of the key or
parameters that have been supplied. Some of those checks use the supplied
modulus value even if it has already been found to be too large.
A new limit has been added to DH_check of 32,768 bits. Supplying a
key/parameters with a modulus over this size will simply cause DH_check()
to fail.
(CVE-2023-3446)
[Matt Caswell]
*) Mitigate for the time it takes for `OBJ_obj2txt` to translate gigantic
OBJECT IDENTIFIER sub-identifiers to canonical numeric text form.
......
......@@ -4,6 +4,8 @@
This file gives a brief overview of the major changes between each OpenSSL
release. For more details please read the CHANGES file.
o Fix excessive time spent checking DH q parameter value (CVE-2023-3817)
o Fix DH_check() excessive time with over sized modulus (CVE-2023-3446)
o Fixed documentation of X509_VERIFY_PARAM_add0_policy() (CVE-2023-0466)
o Mitigate for very slow `OBJ_obj2txt()` performance with gigantic
OBJECT IDENTIFIER sub-identities. (CVE-2023-2650)
......
......@@ -97,10 +97,16 @@ int DH_check_ex(const DH *dh)
int DH_check(const DH *dh, int *ret)
{
int ok = 0, r;
int ok = 0, r, q_good = 0;
BN_CTX *ctx = NULL;
BIGNUM *t1 = NULL, *t2 = NULL;
/* Don't do any checks at all with an excessively large modulus */
if (BN_num_bits(dh->p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) {
DHerr(DH_F_DH_CHECK, DH_R_MODULUS_TOO_LARGE);
return 0;
}
if (!DH_check_params(dh, ret))
return 0;
......@@ -113,7 +119,14 @@ int DH_check(const DH *dh, int *ret)
if (t2 == NULL)
goto err;
if (dh->q) {
if (dh->q != NULL) {
if (BN_ucmp(dh->p, dh->q) > 0)
q_good = 1;
else
*ret |= DH_CHECK_INVALID_Q_VALUE;
}
if (q_good) {
if (BN_cmp(dh->g, BN_value_one()) <= 0)
*ret |= DH_NOT_SUITABLE_GENERATOR;
else if (BN_cmp(dh->g, dh->p) >= 0)
......
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
......@@ -18,6 +18,7 @@ static const ERR_STRING_DATA DH_str_functs[] = {
{ERR_PACK(ERR_LIB_DH, DH_F_DHPARAMS_PRINT_FP, 0), "DHparams_print_fp"},
{ERR_PACK(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, 0),
"dh_builtin_genparams"},
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK, 0), "DH_check"},
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_EX, 0), "DH_check_ex"},
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PARAMS_EX, 0), "DH_check_params_ex"},
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PUB_KEY_EX, 0), "DH_check_pub_key_ex"},
......
......@@ -402,6 +402,7 @@ CT_F_SCT_SET_VERSION:104:SCT_set_version
DH_F_COMPUTE_KEY:102:compute_key
DH_F_DHPARAMS_PRINT_FP:101:DHparams_print_fp
DH_F_DH_BUILTIN_GENPARAMS:106:dh_builtin_genparams
DH_F_DH_CHECK:126:DH_check
DH_F_DH_CHECK_EX:121:DH_check_ex
DH_F_DH_CHECK_PARAMS_EX:122:DH_check_params_ex
DH_F_DH_CHECK_PUB_KEY_EX:123:DH_check_pub_key_ex
......
......@@ -29,6 +29,9 @@ extern "C" {
# ifndef OPENSSL_DH_MAX_MODULUS_BITS
# define OPENSSL_DH_MAX_MODULUS_BITS 10000
# endif
# ifndef OPENSSL_DH_CHECK_MAX_MODULUS_BITS
# define OPENSSL_DH_CHECK_MAX_MODULUS_BITS 32768
# endif
# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024
......
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
......@@ -30,6 +30,7 @@ int ERR_load_DH_strings(void);
# define DH_F_COMPUTE_KEY 102
# define DH_F_DHPARAMS_PRINT_FP 101
# define DH_F_DH_BUILTIN_GENPARAMS 106
# define DH_F_DH_CHECK 126
# define DH_F_DH_CHECK_EX 121
# define DH_F_DH_CHECK_PARAMS_EX 122
# define DH_F_DH_CHECK_PUB_KEY_EX 123
......
......@@ -63,7 +63,7 @@ static int dh_test(void)
|| !TEST_true(DH_set0_pqg(dh, p, q, g)))
goto err1;
if (!DH_check(dh, &i))
if (!TEST_true(DH_check(dh, &i)))
goto err2;
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|| !TEST_false(i & DH_CHECK_P_NOT_SAFE_PRIME)
......@@ -123,6 +123,17 @@ static int dh_test(void)
/* check whether the public key was calculated correctly */
TEST_uint_eq(BN_get_word(pub_key2), 3331L);
/* Modulus of size: dh check max modulus bits + 1 */
if (!TEST_true(BN_set_word(p, 1))
|| !TEST_true(BN_lshift(p, p, OPENSSL_DH_CHECK_MAX_MODULUS_BITS)))
goto err3;
/*
* We expect no checks at all for an excessively large modulus
*/
if (!TEST_false(DH_check(dh, &i)))
goto err3;
/*
* II) key generation
*/
......@@ -137,7 +148,7 @@ static int dh_test(void)
goto err3;
/* ... and check whether it is valid */
if (!DH_check(a, &i))
if (!TEST_true(DH_check(a, &i)))
goto err3;
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|| !TEST_false(i & DH_CHECK_P_NOT_SAFE_PRIME)
......