wolfSSL — Out-of-Bounds Read and Write in DTLS 1.3 Client NewSessionTicket Skip After Rejected ECH
A wolfSSL DTLS 1.3 client whose ECH offer was not accepted skips NewSessionTicket messages by advancing the record cursor by the message size plus the record padding, which the record layer also counts. The input-buffer index ends past the buffered data, and later datagrams are parsed against corrupted buffer state.
- Advisory
- BYTERAY-2026-0315
- CWE
- CWE-125
- CVSS
- 8.1 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-27
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with HAVE_ECH, WOLFSSL_DTLS13 and session tickets; DTLS 1.3 clients that installed ECH configurations
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
A wolfSSL client that has ECH configurations installed ignores a NewSessionTicket when the server did not accept ECH. DoTls13NewSessionTicket() does this by advancing the caller's input index and returning success. The amount it adds is the message size plus ssl->keys.padSz, the padding and tag length of the current record.
The record layer accounts for padSz itself, once when it trims the record content and again when it finishes the record. The skip therefore counts it one time too many. On the DTLS 1.3 path nothing re-checks the index after the handler returns, so record processing ends with the input-buffer index greater than the buffer length, and still reports success.
The buffer bookkeeping that runs next treats the negative remainder as valid. It frees the dynamic input buffer, falls back to the 5-byte static buffer, and records a length close to 4 GB. A server can use this to cause an out-of-bounds read in the client on the next datagram and, under further conditions, an out-of-bounds write. Default builds are not affected: ECH and DTLS 1.3 are both off by default.
Affected Products and Versions
- Component:
src/tls13.c,DoTls13NewSessionTicket(), the branch that skips the ticket when ECH was not accepted; the cursor is carried forward by_Dtls13HandshakeRecv()andDtls13HandshakeRecv()insrc/dtls13.cand byDoProcessReplyEx()insrc/internal.c. - Required build:
HAVE_ECH(--enable-ech),WOLFSSL_DTLS13(--enable-dtls13) and session tickets. - Required configuration: a DTLS 1.3 client that installed ECH configurations with
wolfSSL_SetEchConfigs(). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild is not affected. - Other releases were not checked.
Technical Details
The skip is at the top of DoTls13NewSessionTicket() (src/tls13.c:14462-14465):
#ifdef HAVE_ECH
/* ignore session ticket when ECH is rejected */
if (ssl->echConfigs != NULL && !ssl->options.disableECH &&
!ssl->options.echAccepted) {
*inOutIdx += size + ssl->keys.padSz;
return 0;
}
#endif
size is the handshake message body. ssl->keys.padSz belongs to the record, not to the message, and the record layer handles it. Adding it here moves the index past the handshake content by padSz bytes.
How the over-advance turns into corrupted buffer state:
- For a protected TLS 1.3 record,
removeMsgInnerPadding()(src/internal.c:24950) setsssl->keys.padSzto the content-type byte, the zero padding and the AEAD tag. The sender chooses the amount of zero padding. DoProcessReplyEx()subtractspadSzfromssl->curSizeonce (src/internal.c:26101-26103), so the handshake content it dispatches ends where the padding begins.DoTls13HandShakeMsgType()checks that the message fits only on entry (src/tls13.c:15831). It does not check how far the handler moved the index.- The skip branch adds
size + padSzand returns 0. _Dtls13HandshakeRecv()stores the index as the processed size (src/dtls13.c:2043), andDtls13HandshakeRecv()adds that to the caller's index (src/dtls13.c:2071). Neither compares it with the data available.- The end-of-record step in
DoProcessReplyEx()addspadSztossl->buffers.inputBuffer.idx(src/internal.c:26446). The index is now greater thaninputBuffer.length, and the function returns success (src/internal.c:26449). ShrinkInputBuffer()computes the unread length as a signedlength - idx, which is negative. Its guard tests only an upper bound (src/internal.c:12474-12476). The function frees the dynamic buffer, points the input buffer at the static buffer, and stores the negative value as an unsigned length (src/internal.c:12528-12535).- For the next datagram, the DTLS record-header parsers compare
length - idxas unsigned values (src/internal.c:13416,src/internal.c:13266), and the comparison passes against the oversized length. The header is copied frombuffer + idx(src/internal.c:13431), outside the static buffer. If parsing continues, the record is decrypted in place at that position (src/internal.c:25940).
The stream (non-DTLS) branch of GetInputData_ex() contains a check for a negative unread length (src/internal.c:24669). The DTLS branch has no equivalent.
Reachability and Preconditions
- Build with
HAVE_ECH,WOLFSSL_DTLS13and session tickets. - The client application installed ECH configurations with
wolfSSL_SetEchConfigs()and connects over DTLS 1.3. - The server did not accept the client's ECH offer, so
ssl->options.echAcceptedis clear when the ticket arrives. - Attacker position: the DTLS 1.3 server the client connects to, whether malicious, compromised or non-conforming. The record that carries the ticket is AEAD-protected, so a party without the traffic keys cannot forge it. An on-path attacker who is not the server is not in a position to do this.
- The size of the over-advance is the record's
padSz, which includes zero padding chosen by the sender. - The out-of-bounds write additionally requires the server to influence client memory contents near the out-of-bounds position, which makes that outcome harder to reach than the read.
- No user interaction beyond the client connecting to the server.
Impact
Memory corruption in the DTLS 1.3 client, caused by the server. The input-buffer state is left inconsistent, with the live buffer freed and the fallback buffer recorded with a length of about 4 GB. The next datagram produces an out-of-bounds read of a record header. Where processing continues past the header, the in-place record decryption writes up to about 16 KB starting outside the 5-byte static buffer, inside and beyond the client's WOLFSSL object.
The corruption happens while the handshake is being finalized, before the client fails the connection with ECH_REQUIRED_E. The application never receives a usable session, but the memory has already been corrupted. The outcome is a client crash, and code execution in the client cannot be ruled out where the write is reached.
ByteRay reproduced this issue in an instrumented test build.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction is for the skip branch of DoTls13NewSessionTicket() to advance the index by the message size only, because the record layer already accounts for the padding. DoTls13HandShakeMsgType() should also verify after the handler returns that exactly the declared number of bytes was consumed, and the DTLS 1.3 handshake receive functions should reject a processed size that would move the index past the available data.
As defense in depth: ShrinkInputBuffer() should treat a negative unread length as a fatal error, the DTLS branch of GetInputData_ex() should carry the same negative-length check as the stream branch, DoProcessReplyEx() should return an error when the index exceeds the buffer length, and the record-header parsers should not rely on an unsigned subtraction that can wrap.
Workarounds, for builds that cannot be updated: a DTLS 1.3 client that does not install ECH configurations does not take the skip branch, and a build without HAVE_ECH does not contain it. Both give up ECH.
Timeline
- 2026-09-27 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.