wolfSSL — Missing Negative-Length Check in DTLS Input Buffer Refill Path
GetInputData_ex rejects a negative used length or maximum length only in its non-DTLS branch, and the DTLS fast path in the record loop skips the refill call when an unsigned length difference is large. A corrupted input buffer descriptor that ends a TLS connection with an error is therefore parsed on DTLS, leading to reads past a 5-byte buffer.
- Advisory
- BYTERAY-2026-0479
- CWE
- CWE-125
- CVSS
- 3.7 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with DTLS (WOLFSSL_DTLS, --enable-dtls); has an effect only after a separate defect leaves the input cursor past the buffered length
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The record layer describes its input buffer with an index and a length. If another defect moves the index past the length, the buffer can be left in an impossible state: the 5-byte static buffer with a length of about 4 GB.
GetInputData_ex() has a check that catches this state and returns BUFFER_ERROR. The check is in the non-DTLS branch only. The DTLS branch has no equivalent. In addition, the DTLS fast path in the record loop computes the bytes available as an unsigned difference, finds it large, and does not call the refill function at all.
No network message can create the corrupted state through this code alone. It needs a separate defect that over-advances the record cursor, such as the one in BYTERAY-2026-0315. When that happens, a TLS connection fails cleanly and a DTLS connection goes on to parse a record header from beyond the static buffer. DTLS is not part of a default build.
Affected Products and Versions
- Component:
src/internal.c,GetInputData_ex()(DTLS branch), the DTLS fast path inDoProcessReplyEx(), andGetDtlsRecordHeader(). - Required build:
WOLFSSL_DTLS(--enable-dtls). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include DTLS. In DTLS builds the asymmetry is unconditional. - Other releases were not checked.
Technical Details
GetInputData_ex() computes usedLength and maxLength as signed values (src/internal.c:24648-24651). The non-DTLS branch then checks them (src/internal.c:24668-24671):
if (usedLength < 0 || maxLength < 0) {
return BUFFER_ERROR;
}
The DTLS branch (src/internal.c:24653-24664) derives its read size from the MTU and performs no sign check. The record loop usually does not reach that function in the corrupted state. Its DTLS fast path computes used = length - idx as an unsigned value (src/internal.c:25685-25686). With idx at 0 and length near 4 GB, used < readSz is false and GetInputData() is skipped (src/internal.c:25687-25695).
Data flow in the corrupted state:
ShrinkInputBuffer()has reset the buffer to the 5-byte static buffer withidx = 0and a length near 4 GB (src/internal.c:12530-12535). See BYTERAY-2026-0480.- The next record enters the DTLS fast path, which skips the refill.
GetDtlsRecordHeader()checkslength - *inOutIdx < DTLS_RECORD_HEADER_SZin unsigned arithmetic (src/internal.c:13416). The difference is about 4 GB, so the check passes.- The header fields are copied from
buffer + *inOutIdx(src/internal.c:13431-13434), past the end of the static buffer. - A header assembled from those bytes that passes the type and version checks can send the record on to in-place decryption (
src/internal.c:25940).
The DTLS 1.3 unified-header parser is not affected. GetDtls13RecordHeader() computes its available size as a signed int and checks it before touching the buffer (src/internal.c:13273-13279), so the same state ends in BUFFER_ERROR. Only the non-unified header path reads out of bounds.
Reachability and Preconditions
- Build with DTLS. The connection is a DTLS connection that is not in SCTP mode.
- The input cursor must already be past the buffered length. This code does not produce that state. The known producer needs a DTLS 1.3 client with ECH configured, a server that did not accept ECH, and a padded post-handshake NewSessionTicket from that server.
- The attacker is the DTLS session peer.
Impact
Without a producer defect there is no effect. With one, the DTLS receiver has no check that turns the corrupted state into a connection error. The result is out-of-bounds reads inside the connection structure, and the in-place decryption path extends this toward writes. On TLS the same state ends in BUFFER_ERROR.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
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 to move the negative-length check in GetInputData_ex() above the DTLS and non-DTLS split so both branches enforce it; to compute used in the DTLS fast path with signed arithmetic and treat idx > length as fatal; and to rewrite the availability check in GetDtlsRecordHeader() so it validates the index against the length before subtracting, as GetDtls13RecordHeader() does. A check at the top of the receive loop that returns BUFFER_ERROR when idx > length would cover any producer. Builds without DTLS are not affected.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.
References
GetInputData_exlength checks at the tested commit- DTLS fast path in the record loop at the tested commit
GetDtlsRecordHeaderavailability check and header copy at the tested commit- BYTERAY-2026-0315, DTLS 1.3 record cursor over-advance when skipping a NewSessionTicket
- BYTERAY-2026-0480, missing negative-length check in
ShrinkInputBuffer