|
| 1 | +Only free the read buffers if we're not using them |
| 2 | + |
| 3 | +If we're part way through processing a record, or the application has |
| 4 | +not released all the records then we should not free our buffer because |
| 5 | +they are still needed. |
| 6 | + |
| 7 | +CVE-2024-4741 |
| 8 | + |
| 9 | +Reviewed-by: Tomas Mraz < [email protected]> |
| 10 | +Reviewed-by: Neil Horman < [email protected]> |
| 11 | +Reviewed-by: Matt Caswell < [email protected]> |
| 12 | +--- |
| 13 | + ssl/record/rec_layer_s3.c | 9 +++++++++ |
| 14 | + ssl/record/record.h | 1 + |
| 15 | + ssl/ssl_lib.c | 3 +++ |
| 16 | + 3 files changed, 13 insertions(+) |
| 17 | + |
| 18 | +diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c |
| 19 | +index 1db1712a09..525c3abf43 100644 |
| 20 | +--- a/ssl/record/rec_layer_s3.c |
| 21 | ++++ b/ssl/record/rec_layer_s3.c |
| 22 | +@@ -81,6 +81,15 @@ int RECORD_LAYER_read_pending(const RECORD_LAYER *rl) |
| 23 | + return SSL3_BUFFER_get_left(&rl->rbuf) != 0; |
| 24 | + } |
| 25 | + |
| 26 | ++int RECORD_LAYER_data_present(const RECORD_LAYER *rl) |
| 27 | ++{ |
| 28 | ++ if (rl->rstate == SSL_ST_READ_BODY) |
| 29 | ++ return 1; |
| 30 | ++ if (RECORD_LAYER_processed_read_pending(rl)) |
| 31 | ++ return 1; |
| 32 | ++ return 0; |
| 33 | ++} |
| 34 | ++ |
| 35 | + /* Checks if we have decrypted unread record data pending */ |
| 36 | + int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl) |
| 37 | + { |
| 38 | +diff --git a/ssl/record/record.h b/ssl/record/record.h |
| 39 | +index af56206e07..513ab39888 100644 |
| 40 | +--- a/ssl/record/record.h |
| 41 | ++++ b/ssl/record/record.h |
| 42 | +@@ -197,6 +197,7 @@ void RECORD_LAYER_release(RECORD_LAYER *rl); |
| 43 | + int RECORD_LAYER_read_pending(const RECORD_LAYER *rl); |
| 44 | + int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl); |
| 45 | + int RECORD_LAYER_write_pending(const RECORD_LAYER *rl); |
| 46 | ++int RECORD_LAYER_data_present(const RECORD_LAYER *rl); |
| 47 | + void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl); |
| 48 | + void RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl); |
| 49 | + int RECORD_LAYER_is_sslv2_record(RECORD_LAYER *rl); |
| 50 | +diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c |
| 51 | +index 47adc3211c..ff2a40e115 100644 |
| 52 | +--- a/ssl/ssl_lib.c |
| 53 | ++++ b/ssl/ssl_lib.c |
| 54 | +@@ -5247,6 +5247,9 @@ int SSL_free_buffers(SSL *ssl) |
| 55 | + if (RECORD_LAYER_read_pending(rl) || RECORD_LAYER_write_pending(rl)) |
| 56 | + return 0; |
| 57 | + |
| 58 | ++ if (RECORD_LAYER_data_present(rl)) |
| 59 | ++ return 0; |
| 60 | ++ |
| 61 | + RECORD_LAYER_release(rl); |
| 62 | + return 1; |
| 63 | + } |
0 commit comments