71 lines
2.8 KiB
Diff
71 lines
2.8 KiB
Diff
From f40c84cc031796e0469c6294abbf945455084627 Mon Sep 17 00:00:00 2001
|
|
From: hy <12444214+dhjgty@user.noreply.gitee.com>
|
|
Date: Mon, 24 Feb 2025 22:50:29 +0800
|
|
Subject: [PATCH] fix CVE-2024-4741
|
|
Only free the read buffers if we're not using them
|
|
If we're part way through processing a record, or the application has
|
|
not released all the records then we should not free our buffer because
|
|
they are still needed.
|
|
|
|
CVE-2024-4741
|
|
|
|
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
|
Reviewed-by: Neil Horman <nhorman@openssl.org>
|
|
Reviewed-by: Matt Caswell <matt@openssl.org>
|
|
|
|
---
|
|
.../Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c | 9 +++++++++
|
|
CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h | 1 +
|
|
CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c | 3 +++
|
|
3 files changed, 13 insertions(+)
|
|
|
|
diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c
|
|
index 3baf8207..99602b6b 100644
|
|
--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c
|
|
+++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c
|
|
@@ -81,6 +81,15 @@ int RECORD_LAYER_read_pending(const RECORD_LAYER *rl)
|
|
return SSL3_BUFFER_get_left(&rl->rbuf) != 0;
|
|
}
|
|
|
|
+int RECORD_LAYER_data_present(const RECORD_LAYER *rl)
|
|
+{
|
|
+ if (rl->rstate == SSL_ST_READ_BODY)
|
|
+ return 1;
|
|
+ if (RECORD_LAYER_processed_read_pending(rl))
|
|
+ return 1;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
/* Checks if we have decrypted unread record data pending */
|
|
int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl)
|
|
{
|
|
diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h
|
|
index 234656bf..b60f71c8 100644
|
|
--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h
|
|
+++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h
|
|
@@ -205,6 +205,7 @@ void RECORD_LAYER_release(RECORD_LAYER *rl);
|
|
int RECORD_LAYER_read_pending(const RECORD_LAYER *rl);
|
|
int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl);
|
|
int RECORD_LAYER_write_pending(const RECORD_LAYER *rl);
|
|
+int RECORD_LAYER_data_present(const RECORD_LAYER *rl);
|
|
void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl);
|
|
void RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl);
|
|
int RECORD_LAYER_is_sslv2_record(RECORD_LAYER *rl);
|
|
diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c b/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c
|
|
index 5d57f5d2..ac4ae41e 100644
|
|
--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c
|
|
+++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c
|
|
@@ -5489,6 +5489,9 @@ int SSL_free_buffers(SSL *ssl)
|
|
if (RECORD_LAYER_read_pending(rl) || RECORD_LAYER_write_pending(rl))
|
|
return 0;
|
|
|
|
+ if (RECORD_LAYER_data_present(rl))
|
|
+ return 0;
|
|
+
|
|
RECORD_LAYER_release(rl);
|
|
return 1;
|
|
}
|
|
--
|
|
2.33.0
|
|
|