Skip to content

Commit 704f725

Browse files
wblmattcaswell
authored andcommitted
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> (Merged from #24395)
1 parent eb1b744 commit 704f725

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

ssl/record/rec_layer_s3.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ int RECORD_LAYER_read_pending(const RECORD_LAYER *rl)
8181
return SSL3_BUFFER_get_left(&rl->rbuf) != 0;
8282
}
8383

84+
int RECORD_LAYER_data_present(const RECORD_LAYER *rl)
85+
{
86+
if (rl->rstate == SSL_ST_READ_BODY)
87+
return 1;
88+
if (RECORD_LAYER_processed_read_pending(rl))
89+
return 1;
90+
return 0;
91+
}
92+
8493
/* Checks if we have decrypted unread record data pending */
8594
int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl)
8695
{

ssl/record/record.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void RECORD_LAYER_release(RECORD_LAYER *rl);
205205
int RECORD_LAYER_read_pending(const RECORD_LAYER *rl);
206206
int RECORD_LAYER_processed_read_pending(const RECORD_LAYER *rl);
207207
int RECORD_LAYER_write_pending(const RECORD_LAYER *rl);
208+
int RECORD_LAYER_data_present(const RECORD_LAYER *rl);
208209
void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl);
209210
void RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl);
210211
int RECORD_LAYER_is_sslv2_record(RECORD_LAYER *rl);

ssl/ssl_lib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5493,6 +5493,9 @@ int SSL_free_buffers(SSL *ssl)
54935493
if (RECORD_LAYER_read_pending(rl) || RECORD_LAYER_write_pending(rl))
54945494
return 0;
54955495

5496+
if (RECORD_LAYER_data_present(rl))
5497+
return 0;
5498+
54965499
RECORD_LAYER_release(rl);
54975500
return 1;
54985501
}

0 commit comments

Comments
 (0)