← ALL ADVISORIES

LOW BYTERAY-2026-0480Disclosed

wolfSSL — Missing Negative-Length Check in ShrinkInputBuffer

ShrinkInputBuffer computes the bytes left in the input buffer as a signed value and checks it only against an upper limit. A negative value, which means the cursor is already past the buffered data, is accepted: the dynamic buffer is freed and the 5-byte static buffer is installed with a length of about 4 GB.

Advisory
BYTERAY-2026-0480
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), all builds; the known way to reach the function with the cursor past the buffered length needs a TLS 1.3 client built with ECH and session tickets
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

ShrinkInputBuffer() returns the record layer's input buffer to a small static array once a record has been processed. It computes how many bytes are still unread by subtracting the cursor from the length, and declines to shrink when too many remain.

The guard checks only the upper direction. If the cursor is already past the length, the remainder is negative and the guard lets it through. The function then skips the copy of leftover bytes, zeroes and frees the dynamic buffer, points the session at the 5-byte static buffer, and stores the negative remainder as an unsigned length of about 4.29 GB.

The function cannot be reached in that state by itself. Another defect must first move the cursor past the record end; the known one is described in BYTERAY-2026-0315. On stream TLS 1.3 the corrupted state is caught on the next read and the connection fails. On DTLS it is not caught, as described in BYTERAY-2026-0479. The function is in every build. The known producer needs ECH, which is off by default.

Affected Products and Versions

  • Component: src/internal.c, ShrinkInputBuffer().
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • Required build: none for the missing check; a default ./configure build contains the function without it. The known trigger needs a TLS 1.3 client with ECH (--enable-ech) and session tickets. ECH is disabled by default, so the known trigger is not in a default build.
  • Other releases were not checked.

Technical Details

The function starts with the computation and its guard (src/internal.c:12474-12481):

    int usedLength = (int)(ssl->buffers.inputBuffer.length -
                     ssl->buffers.inputBuffer.idx);
    if (!forcedFree && (usedLength > STATIC_BUFFER_LEN ||
            ssl->buffers.clearOutputBuffer.length > 0 ||
            ssl->options.processReply != doProcessInit))
        return;

There is no usedLength < 0 test. GetInputData_ex() has that test in its non-DTLS branch (src/internal.c:24668-24671).

With idx > length:

  1. usedLength is negative, so usedLength > STATIC_BUFFER_LEN is false. The other two clauses are satisfied when the record loop has finished the record.
  2. The copy of leftover bytes is guarded by usedLength > 0 and is skipped (src/internal.c:12520-12524).
  3. The dynamic buffer is zeroed and freed (src/internal.c:12526-12529).
  4. The descriptor is reset to the static buffer with idx = 0 and length = (word32)usedLength (src/internal.c:12530-12535). STATIC_BUFFER_LEN is the record header size, 5 bytes (wolfssl/internal.h:2491).

How the function is reached in that state on the known path: the ECH-skip branch of the NewSessionTicket handler advances the cursor to the physical record end and returns success (src/tls13.c:14462-14465); the TLS 1.3 dispatcher does not re-check consumption (BYTERAY-2026-0478); the record-done branch of DoProcessReplyEx() adds the padding size a second time (src/internal.c:26443-26446) and then calls ShrinkInputBuffer(ssl, NO_FORCED_FREE) (src/internal.c:26479-26480). On stream TLS 1.3 the next pass calls GetInputData_ex() (src/internal.c:25680), whose non-DTLS branch sees the negative used length and returns BUFFER_ERROR.

Reachability and Preconditions

  • The cursor must be past the buffered length when the function is called. No path does this without a separate over-advance defect.
  • Known path: client built with TLS 1.3, ECH and session tickets; ECH configured and not accepted by the server; the handshake is complete.
  • The attacker is the TLS server the client connected to. It sends one padded post-handshake NewSessionTicket record.

Impact

Not reachable on its own. On the known path over stream TLS 1.3, the result is a terminated connection on the client's next read, repeatable on each new connection, and an invalid buffer descriptor in the meantime. No out-of-bounds access occurs on that path in the tested tree, because the check in GetInputData_ex() fails closed. On DTLS that check is absent and the same state leads to out-of-bounds access.

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 a lower-bound check at the top of ShrinkInputBuffer(): treat usedLength < 0 as a fatal internal error and return without freeing the buffer or changing the descriptor. This should be paired with the exact-consumption check in the TLS 1.3 dispatcher, removal of the second padding advance in the record-done branch, and the same negative-length rejection in the DTLS branch of GetInputData_ex(). Building without ECH removes the known producer.

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