|
| 1 | +From 4b73edb6a6244abe110d850832aafc47c93b93e3 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Sreenivasulu Malavathula <v-smalavathu@microsoft.com> |
| 3 | +Date: Mon, 3 Mar 2025 15:59:36 -0600 |
| 4 | +Subject: [PATCH] Address CVE-2024-0727 |
| 5 | + |
| 6 | +--- |
| 7 | + .../OpensslLib/openssl/crypto/dh/dh_check.c | 22 +++++++++++++++++++ |
| 8 | + .../OpensslLib/openssl/crypto/dh/dh_err.c | 4 +++- |
| 9 | + .../OpensslLib/openssl/crypto/dh/dh_key.c | 12 ++++++++++ |
| 10 | + .../openssl/include/openssl/dherr.h | 4 +++- |
| 11 | + 4 files changed, 40 insertions(+), 2 deletions(-) |
| 12 | + |
| 13 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_check.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_check.c |
| 14 | +index 8afa2640..8ea38586 100644 |
| 15 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_check.c |
| 16 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_check.c |
| 17 | +@@ -104,6 +104,15 @@ int DH_check(const DH *dh, int *ret) |
| 18 | + if (!DH_check_params(dh, ret)) |
| 19 | + return 0; |
| 20 | + |
| 21 | ++ *ret = 0; |
| 22 | ++ |
| 23 | ++ /* Don't do any checks at all with an excessively large modulus */ |
| 24 | ++ if (BN_num_bits(dh->p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) { |
| 25 | ++ DHerr(DH_F_DH_CHECK, DH_R_MODULUS_TOO_LARGE); |
| 26 | ++ *ret = DH_CHECK_P_NOT_PRIME; |
| 27 | ++ return 0; |
| 28 | ++ } |
| 29 | ++ |
| 30 | + ctx = BN_CTX_new(); |
| 31 | + if (ctx == NULL) |
| 32 | + goto err; |
| 33 | +@@ -191,6 +200,19 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) |
| 34 | + BN_CTX *ctx = NULL; |
| 35 | + |
| 36 | + *ret = 0; |
| 37 | ++ |
| 38 | ++ /* Don't do any checks at all with an excessively large modulus */ |
| 39 | ++ if (BN_num_bits(dh->p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) { |
| 40 | ++ DHerr(DH_F_DH_CHECK_PUB_KEY, DH_R_MODULUS_TOO_LARGE); |
| 41 | ++ *ret = DH_CHECK_P_NOT_PRIME | DH_CHECK_PUBKEY_INVALID; |
| 42 | ++ return 0; |
| 43 | ++ } |
| 44 | ++ |
| 45 | ++ if (dh->q != NULL && BN_ucmp(dh->p, dh->q) < 0) { |
| 46 | ++ *ret |= DH_CHECK_INVALID_Q_VALUE | DH_CHECK_PUBKEY_INVALID; |
| 47 | ++ return 1; |
| 48 | ++ } |
| 49 | ++ |
| 50 | + ctx = BN_CTX_new(); |
| 51 | + if (ctx == NULL) |
| 52 | + goto err; |
| 53 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_err.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_err.c |
| 54 | +index 7285587b..2b13e9aa 100644 |
| 55 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_err.c |
| 56 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_err.c |
| 57 | +@@ -1,6 +1,6 @@ |
| 58 | + /* |
| 59 | + * Generated by util/mkerr.pl DO NOT EDIT |
| 60 | +- * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. |
| 61 | ++ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. |
| 62 | + * |
| 63 | + * Licensed under the OpenSSL license (the "License"). You may not use |
| 64 | + * this file except in compliance with the License. You can obtain a copy |
| 65 | +@@ -19,6 +19,7 @@ static const ERR_STRING_DATA DH_str_functs[] = { |
| 66 | + {ERR_PACK(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, 0), |
| 67 | + "dh_builtin_genparams"}, |
| 68 | + {ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_EX, 0), "DH_check_ex"}, |
| 69 | ++ {ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PUB_KEY, 0), "DH_check_pub_key"}, |
| 70 | + {ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PARAMS_EX, 0), "DH_check_params_ex"}, |
| 71 | + {ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PUB_KEY_EX, 0), "DH_check_pub_key_ex"}, |
| 72 | + {ERR_PACK(ERR_LIB_DH, DH_F_DH_CMS_DECRYPT, 0), "dh_cms_decrypt"}, |
| 73 | +@@ -81,6 +82,7 @@ static const ERR_STRING_DATA DH_str_reasons[] = { |
| 74 | + {ERR_PACK(ERR_LIB_DH, 0, DH_R_PARAMETER_ENCODING_ERROR), |
| 75 | + "parameter encoding error"}, |
| 76 | + {ERR_PACK(ERR_LIB_DH, 0, DH_R_PEER_KEY_ERROR), "peer key error"}, |
| 77 | ++ {ERR_PACK(ERR_LIB_DH, 0, DH_R_Q_TOO_LARGE), "q too large"}, |
| 78 | + {ERR_PACK(ERR_LIB_DH, 0, DH_R_SHARED_INFO_ERROR), "shared info error"}, |
| 79 | + {ERR_PACK(ERR_LIB_DH, 0, DH_R_UNABLE_TO_CHECK_GENERATOR), |
| 80 | + "unable to check generator"}, |
| 81 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_key.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_key.c |
| 82 | +index 117f2fa8..c77ce1b0 100644 |
| 83 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_key.c |
| 84 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/dh/dh_key.c |
| 85 | +@@ -114,6 +114,12 @@ static int generate_key(DH *dh) |
| 86 | + return 0; |
| 87 | + } |
| 88 | + |
| 89 | ++ if (dh->q != NULL |
| 90 | ++ && BN_num_bits(dh->q) > OPENSSL_DH_MAX_MODULUS_BITS) { |
| 91 | ++ DHerr(DH_F_GENERATE_KEY, DH_R_Q_TOO_LARGE); |
| 92 | ++ return 0; |
| 93 | ++ } |
| 94 | ++ |
| 95 | + ctx = BN_CTX_new(); |
| 96 | + if (ctx == NULL) |
| 97 | + goto err; |
| 98 | +@@ -207,6 +213,12 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) |
| 99 | + goto err; |
| 100 | + } |
| 101 | + |
| 102 | ++ if (dh->q != NULL |
| 103 | ++ && BN_num_bits(dh->q) > OPENSSL_DH_MAX_MODULUS_BITS) { |
| 104 | ++ DHerr(DH_F_COMPUTE_KEY, DH_R_Q_TOO_LARGE); |
| 105 | ++ goto err; |
| 106 | ++ } |
| 107 | ++ |
| 108 | + ctx = BN_CTX_new(); |
| 109 | + if (ctx == NULL) |
| 110 | + goto err; |
| 111 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/include/openssl/dherr.h b/CryptoPkg/Library/OpensslLib/openssl/include/openssl/dherr.h |
| 112 | +index 916b3bed..c37e2106 100644 |
| 113 | +--- a/CryptoPkg/Library/OpensslLib/openssl/include/openssl/dherr.h |
| 114 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/include/openssl/dherr.h |
| 115 | +@@ -1,6 +1,6 @@ |
| 116 | + /* |
| 117 | + * Generated by util/mkerr.pl DO NOT EDIT |
| 118 | +- * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
| 119 | ++ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. |
| 120 | + * |
| 121 | + * Licensed under the OpenSSL license (the "License"). You may not use |
| 122 | + * this file except in compliance with the License. You can obtain a copy |
| 123 | +@@ -31,6 +31,7 @@ int ERR_load_DH_strings(void); |
| 124 | + # define DH_F_DHPARAMS_PRINT_FP 101 |
| 125 | + # define DH_F_DH_BUILTIN_GENPARAMS 106 |
| 126 | + # define DH_F_DH_CHECK_EX 121 |
| 127 | ++# define DH_F_DH_CHECK_PUB_KEY 120 |
| 128 | + # define DH_F_DH_CHECK_PARAMS_EX 122 |
| 129 | + # define DH_F_DH_CHECK_PUB_KEY_EX 123 |
| 130 | + # define DH_F_DH_CMS_DECRYPT 114 |
| 131 | +@@ -81,6 +82,7 @@ int ERR_load_DH_strings(void); |
| 132 | + # define DH_R_NO_PRIVATE_VALUE 100 |
| 133 | + # define DH_R_PARAMETER_ENCODING_ERROR 105 |
| 134 | + # define DH_R_PEER_KEY_ERROR 111 |
| 135 | ++# define DH_R_Q_TOO_LARGE 130 |
| 136 | + # define DH_R_SHARED_INFO_ERROR 113 |
| 137 | + # define DH_R_UNABLE_TO_CHECK_GENERATOR 121 |
| 138 | + |
| 139 | +-- |
| 140 | +2.45.2 |
| 141 | + |
0 commit comments