|
|
ea120b |
From b8b463159d9bcb05505ec128b5c2926ace0b3e92 Mon Sep 17 00:00:00 2001
|
|
|
ea120b |
From: Quentin Armitage <quentin@armitage.org.uk>
|
|
|
ea120b |
Date: Thu, 13 Oct 2022 08:32:17 +0100
|
|
|
ea120b |
Subject: [PATCH] ipvs: Work around OpenSSL memory leak in versions 3.0.0 to
|
|
|
ea120b |
3.0.4
|
|
|
ea120b |
|
|
|
ea120b |
The memory leak was observed with OpenSSL 3.0.1, and it is resolved
|
|
|
ea120b |
by version 3.0.5. Also the leak is not observed in v1.1.1n.
|
|
|
ea120b |
|
|
|
ea120b |
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
|
|
|
ea120b |
---
|
|
|
ea120b |
keepalived/check/check_ssl.c | 20 +++++++++++++++++++-
|
|
|
ea120b |
1 file changed, 19 insertions(+), 1 deletion(-)
|
|
|
ea120b |
|
|
|
ea120b |
diff --git a/keepalived/check/check_ssl.c b/keepalived/check/check_ssl.c
|
|
|
ea120b |
index 917ac0d7..50efa824 100644
|
|
|
ea120b |
--- a/keepalived/check/check_ssl.c
|
|
|
ea120b |
+++ b/keepalived/check/check_ssl.c
|
|
|
ea120b |
@@ -229,7 +229,25 @@ ssl_connect(thread_ref_t thread, int new_req)
|
|
|
ea120b |
BIO_get_fd(req->bio, &bio_fd);
|
|
|
ea120b |
if (fcntl(bio_fd, F_SETFD, fcntl(bio_fd, F_GETFD) | FD_CLOEXEC) == -1)
|
|
|
ea120b |
log_message(LOG_INFO, "Setting CLOEXEC failed on ssl socket - errno %d", errno);
|
|
|
ea120b |
-#ifdef HAVE_SSL_SET0_RBIO
|
|
|
ea120b |
+
|
|
|
ea120b |
+ /* There is a memory leak in openSSL at least in version 3.0.1, which is fixed
|
|
|
ea120b |
+ * by version 3.0.5. It was not present in version 1.1.1n. Since I haven't been
|
|
|
ea120b |
+ * able to identify the OpenSSL patch that resolved the leak, we play safe and
|
|
|
ea120b |
+ * assume it is in versions 3.0.0 up to 3.0.4.
|
|
|
ea120b |
+ * The leak is memory allocated by
|
|
|
ea120b |
+ * p = OPENSSL_malloc(len);
|
|
|
ea120b |
+ * in ssl3_setup_write_buffer() in ssl/record/ssl_buffer.c
|
|
|
ea120b |
+ *
|
|
|
ea120b |
+ * It appears that setting SSL_MODE_RELEASE_BUFFERS causes the memory leak not
|
|
|
ea120b |
+ * to occur.
|
|
|
ea120b |
+ */
|
|
|
ea120b |
+#ifdef OPENSSL_VERSION_MAJOR
|
|
|
ea120b |
+#if OPENSSL_VERSION_MAJOR == 3 && OPENSSL_VERSION_MINOR == 0 && OPENSSL_VERSION_PATCH <= 4
|
|
|
ea120b |
+ SSL_set_mode(req->ssl, SSL_MODE_RELEASE_BUFFERS);
|
|
|
ea120b |
+#endif
|
|
|
ea120b |
+#endif
|
|
|
ea120b |
+
|
|
|
ea120b |
+#if defined HAVE_SSL_SET0_RBIO && defined HAVE_SSL_SET0_WBIO
|
|
|
ea120b |
BIO_up_ref(req->bio);
|
|
|
ea120b |
SSL_set0_rbio(req->ssl, req->bio);
|
|
|
ea120b |
SSL_set0_wbio(req->ssl, req->bio);
|
|
|
ea120b |
--
|
|
|
ea120b |
2.38.1
|
|
|
ea120b |
|