|
| 1 | +--- /dev/null 2024-02-26 19:17:51 |
| 2 | ++++ openssl-1.1.1k-6/SOURCES/openssl-1.1.1k-CVE-2023-5678-fips.patch 2024-02-01 02:02:19 |
| 3 | +@@ -0,0 +1,142 @@ |
| 4 | ++Backport of: |
| 5 | ++ |
| 6 | ++From db925ae2e65d0d925adef429afc37f75bd1c2017 Mon Sep 17 00:00:00 2001 |
| 7 | ++From: Richard Levitte <[email protected]> |
| 8 | ++Date: Fri, 20 Oct 2023 09:18:19 +0200 |
| 9 | ++Subject: [PATCH] Make DH_check_pub_key() and DH_generate_key() safer yet |
| 10 | ++ |
| 11 | ++We already check for an excessively large P in DH_generate_key(), but not in |
| 12 | ++DH_check_pub_key(), and none of them check for an excessively large Q. |
| 13 | ++ |
| 14 | ++This change adds all the missing excessive size checks of P and Q. |
| 15 | ++ |
| 16 | ++It's to be noted that behaviours surrounding excessively sized P and Q |
| 17 | ++differ. DH_check() raises an error on the excessively sized P, but only |
| 18 | ++sets a flag for the excessively sized Q. This behaviour is mimicked in |
| 19 | ++DH_check_pub_key(). |
| 20 | ++ |
| 21 | ++Reviewed-by: Tomas Mraz <[email protected]> |
| 22 | ++Reviewed-by: Matt Caswell <[email protected]> |
| 23 | ++Reviewed-by: Hugo Landau <[email protected]> |
| 24 | ++(Merged from https://github.com/openssl/openssl/pull/22518) |
| 25 | ++ |
| 26 | ++(cherry picked from commit ddeb4b6c6d527e54ce9a99cba785c0f7776e54b6) |
| 27 | ++--- |
| 28 | ++ crypto/dh/dh_check.c | 12 ++++++++++++ |
| 29 | ++ crypto/dh/dh_err.c | 3 ++- |
| 30 | ++ crypto/dh/dh_key.c | 12 ++++++++++++ |
| 31 | ++ crypto/err/openssl.txt | 1 + |
| 32 | ++ include/crypto/dherr.h | 2 +- |
| 33 | ++ include/openssl/dh.h | 6 +++--- |
| 34 | ++ include/openssl/dherr.h | 3 ++- |
| 35 | ++ 7 files changed, 33 insertions(+), 6 deletions(-) |
| 36 | ++ |
| 37 | ++--- a/crypto/dh/dh_check.c |
| 38 | +++++ b/crypto/dh/dh_check.c |
| 39 | ++@@ -201,6 +201,19 @@ int DH_check_pub_key(const DH *dh, const |
| 40 | ++ if (ctx == NULL) |
| 41 | ++ goto err; |
| 42 | ++ BN_CTX_start(ctx); |
| 43 | +++ |
| 44 | +++ /* Don't do any checks at all with an excessively large modulus */ |
| 45 | +++ if (BN_num_bits(dh->p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) { |
| 46 | +++ DHerr(DH_F_DH_CHECK, DH_R_MODULUS_TOO_LARGE); |
| 47 | +++ *ret = DH_MODULUS_TOO_LARGE | DH_CHECK_PUBKEY_INVALID; |
| 48 | +++ goto err; |
| 49 | +++ } |
| 50 | +++ |
| 51 | +++ if (dh->q != NULL && BN_ucmp(dh->p, dh->q) < 0) { |
| 52 | +++ *ret |= DH_CHECK_INVALID_Q_VALUE | DH_CHECK_PUBKEY_INVALID; |
| 53 | +++ goto out; |
| 54 | +++ } |
| 55 | +++ |
| 56 | ++ tmp = BN_CTX_get(ctx); |
| 57 | ++ if (tmp == NULL || !BN_set_word(tmp, 1)) |
| 58 | ++ goto err; |
| 59 | ++@@ -219,6 +232,7 @@ int DH_check_pub_key(const DH *dh, const |
| 60 | ++ *ret |= DH_CHECK_PUBKEY_INVALID; |
| 61 | ++ } |
| 62 | ++ |
| 63 | +++ out: |
| 64 | ++ ok = 1; |
| 65 | ++ err: |
| 66 | ++ BN_CTX_end(ctx); |
| 67 | ++--- a/crypto/dh/dh_err.c |
| 68 | +++++ b/crypto/dh/dh_err.c |
| 69 | ++@@ -82,6 +82,7 @@ static const ERR_STRING_DATA DH_str_reas |
| 70 | ++ {ERR_PACK(ERR_LIB_DH, 0, DH_R_PARAMETER_ENCODING_ERROR), |
| 71 | ++ "parameter encoding error"}, |
| 72 | ++ {ERR_PACK(ERR_LIB_DH, 0, DH_R_PEER_KEY_ERROR), "peer key error"}, |
| 73 | +++ {ERR_PACK(ERR_LIB_DH, 0, DH_R_Q_TOO_LARGE), "q too large"}, |
| 74 | ++ {ERR_PACK(ERR_LIB_DH, 0, DH_R_SHARED_INFO_ERROR), "shared info error"}, |
| 75 | ++ {ERR_PACK(ERR_LIB_DH, 0, DH_R_UNABLE_TO_CHECK_GENERATOR), |
| 76 | ++ "unable to check generator"}, |
| 77 | ++--- a/crypto/dh/dh_key.c |
| 78 | +++++ b/crypto/dh/dh_key.c |
| 79 | ++@@ -87,6 +87,12 @@ static int generate_key(DH *dh) |
| 80 | ++ return 0; |
| 81 | ++ } |
| 82 | ++ |
| 83 | +++ if (dh->q != NULL |
| 84 | +++ && BN_num_bits(dh->q) > OPENSSL_DH_MAX_MODULUS_BITS) { |
| 85 | +++ DHerr(DH_F_GENERATE_KEY, DH_R_Q_TOO_LARGE); |
| 86 | +++ return 0; |
| 87 | +++ } |
| 88 | +++ |
| 89 | ++ ctx = BN_CTX_new(); |
| 90 | ++ if (ctx == NULL) |
| 91 | ++ goto err; |
| 92 | ++@@ -180,6 +186,12 @@ static int compute_key(unsigned char *ke |
| 93 | ++ goto err; |
| 94 | ++ } |
| 95 | ++ |
| 96 | +++ if (dh->q != NULL |
| 97 | +++ && BN_num_bits(dh->q) > OPENSSL_DH_MAX_MODULUS_BITS) { |
| 98 | +++ DHerr(DH_F_COMPUTE_KEY, DH_R_Q_TOO_LARGE); |
| 99 | +++ goto err; |
| 100 | +++ } |
| 101 | +++ |
| 102 | ++ ctx = BN_CTX_new(); |
| 103 | ++ if (ctx == NULL) |
| 104 | ++ goto err; |
| 105 | ++--- a/crypto/err/openssl.txt |
| 106 | +++++ b/crypto/err/openssl.txt |
| 107 | ++@@ -2110,6 +2110,7 @@ DH_R_NO_PARAMETERS_SET:107:no parameters |
| 108 | ++ DH_R_NO_PRIVATE_VALUE:100:no private value |
| 109 | ++ DH_R_PARAMETER_ENCODING_ERROR:105:parameter encoding error |
| 110 | ++ DH_R_PEER_KEY_ERROR:111:peer key error |
| 111 | +++DH_R_Q_TOO_LARGE:130:q too large |
| 112 | ++ DH_R_SHARED_INFO_ERROR:113:shared info error |
| 113 | ++ DH_R_UNABLE_TO_CHECK_GENERATOR:121:unable to check generator |
| 114 | ++ DSA_R_BAD_Q_VALUE:102:bad q value |
| 115 | ++--- a/include/openssl/dh.h |
| 116 | +++++ b/include/openssl/dh.h |
| 117 | ++@@ -71,14 +71,16 @@ DECLARE_ASN1_ITEM(DHparams) |
| 118 | ++ /* #define DH_GENERATOR_3 3 */ |
| 119 | ++ # define DH_GENERATOR_5 5 |
| 120 | ++ |
| 121 | ++-/* DH_check error codes */ |
| 122 | +++/* DH_check error codes, some of them shared with DH_check_pub_key */ |
| 123 | ++ # define DH_CHECK_P_NOT_PRIME 0x01 |
| 124 | ++ # define DH_CHECK_P_NOT_SAFE_PRIME 0x02 |
| 125 | ++ # define DH_UNABLE_TO_CHECK_GENERATOR 0x04 |
| 126 | ++ # define DH_NOT_SUITABLE_GENERATOR 0x08 |
| 127 | ++ # define DH_CHECK_Q_NOT_PRIME 0x10 |
| 128 | ++-# define DH_CHECK_INVALID_Q_VALUE 0x20 |
| 129 | +++# define DH_CHECK_INVALID_Q_VALUE 0x20 /* +DH_check_pub_key */ |
| 130 | ++ # define DH_CHECK_INVALID_J_VALUE 0x40 |
| 131 | +++# define DH_MODULUS_TOO_SMALL 0x80 |
| 132 | +++# define DH_MODULUS_TOO_LARGE 0x100 /* +DH_check_pub_key */ |
| 133 | ++ |
| 134 | ++ /* DH_check_pub_key error codes */ |
| 135 | ++ # define DH_CHECK_PUBKEY_TOO_SMALL 0x01 |
| 136 | ++--- a/include/openssl/dherr.h |
| 137 | +++++ b/include/openssl/dherr.h |
| 138 | ++@@ -82,6 +82,7 @@ int ERR_load_DH_strings(void); |
| 139 | ++ # define DH_R_NO_PRIVATE_VALUE 100 |
| 140 | ++ # define DH_R_PARAMETER_ENCODING_ERROR 105 |
| 141 | ++ # define DH_R_PEER_KEY_ERROR 111 |
| 142 | +++# define DH_R_Q_TOO_LARGE 130 |
| 143 | ++ # define DH_R_SHARED_INFO_ERROR 113 |
| 144 | ++ # define DH_R_UNABLE_TO_CHECK_GENERATOR 121 |
| 145 | ++ |
0 commit comments