|
| 1 | +From e7765e5647ee29d21ec0ea0ccc0c8320190e0695 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> |
| 3 | +Date: Fri, 11 Oct 2024 17:37:49 +0000 |
| 4 | +Subject: [PATCH] MONGO: Fix infinite loop during TLS operation |
| 5 | + |
| 6 | +--- |
| 7 | + .../include/asio/ssl/detail/impl/engine.ipp | 26 ++++++++++++++----- |
| 8 | + .../asio/include/asio/ssl/error.hpp | 24 ++++++++++++----- |
| 9 | + .../asio/include/asio/ssl/impl/error.ipp | 2 ++ |
| 10 | + 3 files changed, 40 insertions(+), 12 deletions(-) |
| 11 | + |
| 12 | +diff --git a/src/third_party/asio-master/asio/include/asio/ssl/detail/impl/engine.ipp b/src/third_party/asio-master/asio/include/asio/ssl/detail/impl/engine.ipp |
| 13 | +index e60e8d6f88e..315bb287043 100644 |
| 14 | +--- a/src/third_party/asio-master/asio/include/asio/ssl/detail/impl/engine.ipp |
| 15 | ++++ b/src/third_party/asio-master/asio/include/asio/ssl/detail/impl/engine.ipp |
| 16 | +@@ -240,14 +240,23 @@ engine::want engine::perform(int (engine::* op)(void*, std::size_t), |
| 17 | + { |
| 18 | + ec = asio::error_code(sys_error, |
| 19 | + asio::error::get_ssl_category()); |
| 20 | +- return want_nothing; |
| 21 | ++ return pending_output_after > pending_output_before |
| 22 | ++ ? want_output : want_nothing; |
| 23 | + } |
| 24 | + |
| 25 | + if (ssl_error == SSL_ERROR_SYSCALL) |
| 26 | + { |
| 27 | +- ec = asio::error_code(sys_error, |
| 28 | +- asio::error::get_system_category()); |
| 29 | +- return want_nothing; |
| 30 | ++ if (sys_error == 0) |
| 31 | ++ { |
| 32 | ++ ec = asio::ssl::error::unspecified_system_error; |
| 33 | ++ } |
| 34 | ++ else |
| 35 | ++ { |
| 36 | ++ ec = asio::error_code(sys_error, |
| 37 | ++ asio::error::get_ssl_category()); |
| 38 | ++ } |
| 39 | ++ return pending_output_after > pending_output_before |
| 40 | ++ ? want_output : want_nothing; |
| 41 | + } |
| 42 | + |
| 43 | + if (result > 0 && bytes_transferred) |
| 44 | +@@ -268,16 +277,21 @@ engine::want engine::perform(int (engine::* op)(void*, std::size_t), |
| 45 | + ec = asio::error_code(); |
| 46 | + return want_input_and_retry; |
| 47 | + } |
| 48 | +- else if (::SSL_get_shutdown(ssl_) & SSL_RECEIVED_SHUTDOWN) |
| 49 | ++ else if (ssl_error == SSL_ERROR_ZERO_RETURN) |
| 50 | + { |
| 51 | + ec = asio::error::eof; |
| 52 | + return want_nothing; |
| 53 | + } |
| 54 | +- else |
| 55 | ++ else if (ssl_error == SSL_ERROR_NONE) |
| 56 | + { |
| 57 | + ec = asio::error_code(); |
| 58 | + return want_nothing; |
| 59 | + } |
| 60 | ++ else |
| 61 | ++ { |
| 62 | ++ ec = asio::ssl::error::unexpected_result; |
| 63 | ++ return want_nothing; |
| 64 | ++ } |
| 65 | + } |
| 66 | + |
| 67 | + int engine::do_accept(void*, std::size_t) |
| 68 | +diff --git a/src/third_party/asio-master/asio/include/asio/ssl/error.hpp b/src/third_party/asio-master/asio/include/asio/ssl/error.hpp |
| 69 | +index 6165c5cf764..9cbf7d7fae8 100644 |
| 70 | +--- a/src/third_party/asio-master/asio/include/asio/ssl/error.hpp |
| 71 | ++++ b/src/third_party/asio-master/asio/include/asio/ssl/error.hpp |
| 72 | +@@ -44,12 +44,24 @@ enum stream_errors |
| 73 | + { |
| 74 | + #if defined(GENERATING_DOCUMENTATION) |
| 75 | + /// The underlying stream closed before the ssl stream gracefully shut down. |
| 76 | +- stream_truncated |
| 77 | +-#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL) |
| 78 | +- stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ) |
| 79 | +-#else |
| 80 | +- stream_truncated = 1 |
| 81 | +-#endif |
| 82 | ++ stream_truncated, |
| 83 | ++ |
| 84 | ++ /// The underlying SSL library returned a system error without providing |
| 85 | ++ /// further information. |
| 86 | ++ unspecified_system_error, |
| 87 | ++ |
| 88 | ++ /// The underlying SSL library generated an unexpected result from a function |
| 89 | ++ /// call. |
| 90 | ++ unexpected_result |
| 91 | ++#else // defined(GENERATING_DOCUMENTATION) |
| 92 | ++# if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL) |
| 93 | ++ stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ), |
| 94 | ++# else |
| 95 | ++ stream_truncated = 1, |
| 96 | ++# endif |
| 97 | ++ unspecified_system_error = 2, |
| 98 | ++ unexpected_result = 3 |
| 99 | ++#endif // defined(GENERATING_DOCUMENTATION) |
| 100 | + }; |
| 101 | + |
| 102 | + extern ASIO_DECL |
| 103 | +diff --git a/src/third_party/asio-master/asio/include/asio/ssl/impl/error.ipp b/src/third_party/asio-master/asio/include/asio/ssl/impl/error.ipp |
| 104 | +index 98e8c91b43b..01ab34e0655 100644 |
| 105 | +--- a/src/third_party/asio-master/asio/include/asio/ssl/impl/error.ipp |
| 106 | ++++ b/src/third_party/asio-master/asio/include/asio/ssl/impl/error.ipp |
| 107 | +@@ -76,6 +76,8 @@ public: |
| 108 | + switch (value) |
| 109 | + { |
| 110 | + case stream_truncated: return "stream truncated"; |
| 111 | ++ case unspecified_system_error: return "unspecified system error"; |
| 112 | ++ case unexpected_result: return "unexpected result"; |
| 113 | + default: return "asio.ssl.stream error"; |
| 114 | + } |
| 115 | + } |
| 116 | +-- |
| 117 | +2.34.1 |
| 118 | + |
0 commit comments