Projects
home:rottame:vhosts-ng
openssl-1_1
openssl-CVE-2026-54874.patch
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File openssl-CVE-2026-54874.patch of Package openssl-1_1
commit 9dc8677c4cce2a3e5250435863f2f99d03bc43b0 Author: Matt Caswell <matt@openssl.foundation> Date: Tue Jun 23 17:21:48 2026 +0100 Avoid full read buffer allocation when buffering DTLS records dtls1_buffer_record() is used to hold onto a DTLS record across three different scenarios: a record arriving early for the next epoch while a handshake is in progress, re-queuing a record once the epoch catches up and it has been decrypted, and application data arriving between ChangeCipherSpec and Finished. In all three cases it took ownership of the entire live read buffer (sized for the largest possible record, ~16.7KB) and allocated a brand new one to carry on reading, regardless of how small the buffered record actually was. With each of the three queues capped at 100 entries, a peer could send a stream of tiny bogus records and force a disproportionate amount of heap allocation per connection. Instead, copy only the record's own on-wire bytes (header plus ciphertext, or header plus plaintext for an already-decrypted record) into the queue entry, and leave the live read buffer untouched. On retrieval, copy those bytes back into the live buffer and rebase any SSL3_RECORD data/input pointers that pointed into the original packet, rather than handing out a pointer to a standalone allocation. Memory use is now proportional to what the peer actually sends. Fixes CVE-2026-54874 Assisted-by: Claude:claude-sonnet-4-6 Assisted-by: Claude:claude-opus-5 Index: openssl-1.1.1w/ssl/record/rec_layer_d1.c =================================================================== --- openssl-1.1.1w.orig/ssl/record/rec_layer_d1.c +++ openssl-1.1.1w/ssl/record/rec_layer_d1.c @@ -70,21 +70,21 @@ void DTLS_RECORD_LAYER_clear(RECORD_LAYE while ((item = pqueue_pop(d->unprocessed_rcds.q)) != NULL) { rdata = (DTLS1_RECORD_DATA *)item->data; - OPENSSL_free(rdata->rbuf.buf); + OPENSSL_free(rdata->packet); OPENSSL_free(item->data); pitem_free(item); } while ((item = pqueue_pop(d->processed_rcds.q)) != NULL) { rdata = (DTLS1_RECORD_DATA *)item->data; - OPENSSL_free(rdata->rbuf.buf); + OPENSSL_free(rdata->packet); OPENSSL_free(item->data); pitem_free(item); } while ((item = pqueue_pop(d->buffered_app_data.q)) != NULL) { rdata = (DTLS1_RECORD_DATA *)item->data; - OPENSSL_free(rdata->rbuf.buf); + OPENSSL_free(rdata->packet); OPENSSL_free(item->data); pitem_free(item); } @@ -126,26 +126,60 @@ static int dtls1_copy_record(SSL *s, pit rdata = (DTLS1_RECORD_DATA *)item->data; - SSL3_BUFFER_release(&s->rlayer.rbuf); + /* + * The record was read into a read buffer at least this size, so it must fit + * - see the length checks in ssl3_read_n(). Verify it rather than risk + * overrunning the buffer if that ever ceases to hold. + */ + if (!ossl_assert(rdata->packet_length <= s->rlayer.rbuf.len)) { + OPENSSL_free(rdata->packet); + return 0; + } - s->rlayer.packet = rdata->packet; + /* + * rdata->packet is a standalone copy of this record's on-wire bytes (see + * dtls1_buffer_record()). Copy it into the live read buffer so that + * s->rlayer.packet continues to point inside s->rlayer.rbuf.buf, as it + * does for every other record, then free our standalone copy. + */ + memcpy(s->rlayer.rbuf.buf, rdata->packet, rdata->packet_length); + s->rlayer.rbuf.offset = 0; + s->rlayer.rbuf.left = 0; + s->rlayer.packet = s->rlayer.rbuf.buf; s->rlayer.packet_length = rdata->packet_length; - memcpy(&s->rlayer.rbuf, &(rdata->rbuf), sizeof(SSL3_BUFFER)); memcpy(&s->rlayer.rrec, &(rdata->rrec), sizeof(SSL3_RECORD)); + /* + * dtls1_buffer_record() rebased rrec.data/input onto rdata->packet if they + * pointed into this record's own bytes, so translate them again onto the + * record's new location in the read buffer. Anything still pointing + * outside rdata->packet is either a separate allocation (rr->comp) or a + * leftover from a previously processed record that will be overwritten + * before use, so leave it alone. + */ + if (rdata->rrec.data >= rdata->packet + && rdata->rrec.data < rdata->packet + rdata->packet_length) + s->rlayer.rrec[0].data = s->rlayer.packet + (rdata->rrec.data - rdata->packet); + if (rdata->rrec.input >= rdata->packet + && rdata->rrec.input < rdata->packet + rdata->packet_length) + s->rlayer.rrec[0].input = s->rlayer.packet + (rdata->rrec.input - rdata->packet); + + OPENSSL_free(rdata->packet); + /* Set proper sequence number for mac calculation */ - memcpy(&(s->rlayer.read_sequence[2]), &(rdata->packet[5]), 6); + memcpy(&(s->rlayer.read_sequence[2]), &(s->rlayer.packet[5]), 6); return 1; } -int dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority) +int dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority, + size_t limit) { DTLS1_RECORD_DATA *rdata; pitem *item; /* Limit the size of the queue to prevent DOS attacks */ - if (pqueue_size(queue->q) >= 100) + if (pqueue_size(queue->q) >= limit) return 0; rdata = OPENSSL_malloc(sizeof(*rdata)); @@ -158,11 +192,38 @@ int dtls1_buffer_record(SSL *s, record_p return -1; } - rdata->packet = s->rlayer.packet; + /* + * Take a copy of just this record's own on-wire bytes - the header plus the + * record body, which for an already-processed record holds the plaintext + * decrypted in place - rather than the whole (much larger) read buffer. The + * live s->rlayer.rbuf is left untouched and continues to be used for + * subsequent reads. + */ rdata->packet_length = s->rlayer.packet_length; - memcpy(&(rdata->rbuf), &s->rlayer.rbuf, sizeof(SSL3_BUFFER)); + rdata->packet = OPENSSL_memdup(s->rlayer.packet, s->rlayer.packet_length); + if (rdata->packet == NULL) { + OPENSSL_free(rdata); + pitem_free(item); + SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DTLS1_BUFFER_RECORD, + ERR_R_MALLOC_FAILURE); + return -1; + } memcpy(&(rdata->rrec), &s->rlayer.rrec, sizeof(SSL3_RECORD)); + /* + * The copied rrec.data/input still point into the live read buffer. Rebase + * any that point within this record's own bytes onto our standalone copy, + * so that dtls1_copy_record() can translate them again on retrieval. + * Pointers elsewhere (e.g. into rr->comp, or left over from a previously + * processed record) are not ours to move and are left alone. + */ + if (rdata->rrec.data >= s->rlayer.packet + && rdata->rrec.data < s->rlayer.packet + s->rlayer.packet_length) + rdata->rrec.data = rdata->packet + (rdata->rrec.data - s->rlayer.packet); + if (rdata->rrec.input >= s->rlayer.packet + && rdata->rrec.input < s->rlayer.packet + s->rlayer.packet_length) + rdata->rrec.input = rdata->packet + (rdata->rrec.input - s->rlayer.packet); + item->data = rdata; #ifndef OPENSSL_NO_SCTP @@ -175,22 +236,9 @@ int dtls1_buffer_record(SSL *s, record_p } #endif - s->rlayer.packet = NULL; - s->rlayer.packet_length = 0; - memset(&s->rlayer.rbuf, 0, sizeof(s->rlayer.rbuf)); - memset(&s->rlayer.rrec, 0, sizeof(s->rlayer.rrec)); - - if (!ssl3_setup_buffers(s)) { - /* SSLfatal() already called */ - OPENSSL_free(rdata->rbuf.buf); - OPENSSL_free(rdata); - pitem_free(item); - return -1; - } - if (pqueue_insert(queue->q, item) == NULL) { /* Must be a duplicate so ignore it */ - OPENSSL_free(rdata->rbuf.buf); + OPENSSL_free(rdata->packet); OPENSSL_free(rdata); pitem_free(item); } @@ -201,15 +249,16 @@ int dtls1_buffer_record(SSL *s, record_p int dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue) { pitem *item; + int ret; item = pqueue_pop(queue->q); if (item) { - dtls1_copy_record(s, item); + ret = dtls1_copy_record(s, item); OPENSSL_free(item->data); pitem_free(item); - return 1; + return ret; } return 0; @@ -254,7 +303,13 @@ int dtls1_process_buffered_records(SSL * /* Process all the records. */ while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) { - dtls1_get_unprocessed_record(s); + if (!dtls1_get_unprocessed_record(s)) { + /* + * Should not happen. The record has been dropped, so move on + * to the next one. + */ + continue; + } bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch); if (bitmap == NULL) { /* @@ -293,7 +348,8 @@ int dtls1_process_buffered_records(SSL * } if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds), - SSL3_RECORD_get_seq_num(s->rlayer.rrec)) < 0) { + SSL3_RECORD_get_seq_num(s->rlayer.rrec), + DTLS1_MAX_BUFFERED_RECORDS) < 0) { /* SSLfatal() already called */ return 0; } @@ -401,6 +457,7 @@ int dtls1_read_bytes(SSL *s, int type, i } #endif + /* On failure the record is simply dropped */ dtls1_copy_record(s, item); OPENSSL_free(item->data); @@ -454,7 +511,8 @@ int dtls1_read_bytes(SSL *s, int type, i * data for later processing rather than dropping the connection. */ if (dtls1_buffer_record(s, &(s->rlayer.d->buffered_app_data), - SSL3_RECORD_get_seq_num(rr)) < 0) { + SSL3_RECORD_get_seq_num(rr), + DTLS1_MAX_BUFFERED_RECORDS) < 0) { /* SSLfatal() already called */ return -1; } Index: openssl-1.1.1w/ssl/record/record.h =================================================================== --- openssl-1.1.1w.orig/ssl/record/record.h +++ openssl-1.1.1w/ssl/record/record.h @@ -83,7 +83,6 @@ typedef struct record_pqueue_st { typedef struct dtls1_record_data_st { unsigned char *packet; size_t packet_length; - SSL3_BUFFER rbuf; SSL3_RECORD rrec; #ifndef OPENSSL_NO_SCTP struct bio_dgram_sctp_rcvinfo recordinfo; Index: openssl-1.1.1w/ssl/record/ssl3_record.c =================================================================== --- openssl-1.1.1w.orig/ssl/record/ssl3_record.c +++ openssl-1.1.1w/ssl/record/ssl3_record.c @@ -1812,8 +1812,11 @@ int dtls1_process_record(SSL *s, DTLS1_B * after use :-). */ - /* we have pulled in a full packet so zero things */ - RECORD_LAYER_reset_packet_length(&s->rlayer); + /* + * Leave s->rlayer.packet_length alone: ssl3_read_n() starts each new record + * by resetting it, and it must still describe this record's on-wire bytes + * for dtls1_buffer_record() should this record end up being buffered. + */ /* Mark receipt of record. */ dtls1_record_bitmap_update(s, bitmap); @@ -2019,7 +2022,7 @@ int dtls1_get_record(SSL *s) if ((SSL_in_init(s) || ossl_statem_get_in_handshake(s))) { if (dtls1_buffer_record (s, &(DTLS_RECORD_LAYER_get_unprocessed_rcds(&s->rlayer)), - rr->seq_num) < 0) { + rr->seq_num, DTLS1_MAX_UNPROCESSED_RECORDS) < 0) { /* SSLfatal() already called */ return -1; } @@ -2062,7 +2065,8 @@ int dtls_buffer_listen_record(SSL *s, si rr->data = s->rlayer.packet + DTLS1_RT_HEADER_LENGTH; if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds), - SSL3_RECORD_get_seq_num(s->rlayer.rrec)) <= 0) { + SSL3_RECORD_get_seq_num(s->rlayer.rrec), + DTLS1_MAX_BUFFERED_RECORDS) <= 0) { /* SSLfatal() already called */ return 0; } Index: openssl-1.1.1w/ssl/record/record_local.h =================================================================== --- openssl-1.1.1w.orig/ssl/record/record_local.h +++ openssl-1.1.1w/ssl/record/record_local.h @@ -41,9 +41,19 @@ __owur int ssl3_read_n(SSL *s, size_t n, DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr, unsigned int *is_next_epoch); + +/* + * Limits on the number of records dtls1_buffer_record() will hold, to prevent + * DOS attacks. Records arriving early for the next epoch get a tighter limit: + * a legitimate peer only ever has a small burst of those in flight. + */ +#define DTLS1_MAX_UNPROCESSED_RECORDS 16 +#define DTLS1_MAX_BUFFERED_RECORDS 100 + int dtls1_process_buffered_records(SSL *s); int dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue); -int dtls1_buffer_record(SSL *s, record_pqueue *q, unsigned char *priority); +int dtls1_buffer_record(SSL *s, record_pqueue *q, unsigned char *priority, + size_t limit); void ssl3_record_sequence_update(unsigned char *seq); /* Functions provided by the DTLS1_BITMAP component */
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.