|
| 1 | +From f7a045f3143fc6da2ee66bf52d8df04829590dd4 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Watson Ladd <watsonbladd@gmail.com> |
| 3 | +Date: Wed, 24 Apr 2024 11:26:56 +0100 |
| 4 | +Subject: [PATCH] Only free the read buffers if we're not using them |
| 5 | + |
| 6 | +If we're part way through processing a record, or the application has |
| 7 | +not released all the records then we should not free our buffer because |
| 8 | +they are still needed. |
| 9 | + |
| 10 | +Reviewed-by: Tomas Mraz <tomas@openssl.org> |
| 11 | +Reviewed-by: Neil Horman <nhorman@openssl.org> |
| 12 | +Reviewed-by: Matt Caswell <matt@openssl.org> |
| 13 | +--- |
| 14 | + CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c | 9 +++++++++ |
| 15 | + CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h | 1 + |
| 16 | + CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c | 3 +++ |
| 17 | + 3 files changed, 13 insertions(+) |
| 18 | + |
| 19 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c |
| 20 | +index 1db1712a0..525c3abf4 100644 |
| 21 | +--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c |
| 22 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/rec_layer_s3.c |
| 23 | +@@ -81,6 +81,15 @@ int RECORD_LAYER_read_pending(const RECORD_LAYER *rl) |
| 24 | + return SSL3_BUFFER_get_left(&rl->rbuf) != 0; |
| 25 | + } |
| 26 | + |
| 27 | ++int RECORD_LAYER_data_present(const RECORD_LAYER *rl) |
| 28 | ++{ |
| 29 | ++ if (rl->rstate == SSL_ST_READ_BODY) |
| 30 | ++ return 1; |
| 31 | ++ if (RECORD_LAYER_processed_read_pending(rl)) |
| 32 | ++ return 1; |
| 33 | ++ return 0; |
| 34 | ++} |
| 35 | ++ |
| 36 | + /* Checks if we have decrypted unread record data pending */ |
| 37 | + int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl) |
| 38 | + { |
| 39 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h |
| 40 | +index af56206e0..513ab3988 100644 |
| 41 | +--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h |
| 42 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/record/record.h |
| 43 | +@@ -197,6 +197,7 @@ void RECORD_LAYER_release(RECORD_LAYER *rl); |
| 44 | + int RECORD_LAYER_read_pending(const RECORD_LAYER *rl); |
| 45 | + int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl); |
| 46 | + int RECORD_LAYER_write_pending(const RECORD_LAYER *rl); |
| 47 | ++int RECORD_LAYER_data_present(const RECORD_LAYER *rl); |
| 48 | + void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl); |
| 49 | + void RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl); |
| 50 | + int RECORD_LAYER_is_sslv2_record(RECORD_LAYER *rl); |
| 51 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c b/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c |
| 52 | +index c01ad8291..356d65cb6 100644 |
| 53 | +--- a/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c |
| 54 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/ssl/ssl_lib.c |
| 55 | +@@ -5248,6 +5248,9 @@ int SSL_free_buffers(SSL *ssl) |
| 56 | + if (RECORD_LAYER_read_pending(rl) || RECORD_LAYER_write_pending(rl)) |
| 57 | + return 0; |
| 58 | + |
| 59 | ++ if (RECORD_LAYER_data_present(rl)) |
| 60 | ++ return 0; |
| 61 | ++ |
| 62 | + RECORD_LAYER_release(rl); |
| 63 | + return 1; |
| 64 | + } |
| 65 | +-- |
| 66 | +2.33.8 |
| 67 | + |
0 commit comments