[go: nahoru, domu]

Skip to content

Commit

Permalink
Only free the read buffers if we're not using them
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
wbl authored and mattcaswell committed May 28, 2024
1 parent eb1b744 commit 704f725
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ssl/record/rec_layer_s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions ssl/record/record.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ssl/ssl_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -5493,6 +5493,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;
}
Expand Down

0 comments on commit 704f725

Please sign in to comment.