wolfSSL — Heap Out-of-Bounds Read in Session Serialization from Stale Session Ticket Length
wolfSSL_i2d_SSL_SESSION copies ticketLen bytes from the session's ticket pointer without checking that length against the buffer the pointer refers to. After an allocation failure leaves the pointer on the small static ticket buffer with the length of a larger, released ticket, serialization reads past that buffer and places adjacent heap memory in the output blob.
- Advisory
- BYTERAY-2026-0442
- CWE
- CWE-125
- CVSS
- 2.9 (CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), OPENSSL_EXTRA builds with HAVE_SESSION_TICKET, applications that serialize sessions with wolfSSL_i2d_SSL_SESSION
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
A WOLFSSL_SESSION stores a session ticket as a pointer and a 16-bit length. Small tickets live in a static buffer inside the session object. Larger ones live in a separate heap allocation. wolfSSL_i2d_SSL_SESSION() serializes a session for the application and writes the ticket as a length followed by that many bytes.
Two allocation-failure paths, described in BYTERAY-2026-0367, reset the ticket pointer to the static buffer but leave the length of the larger ticket that was just released. The serializer trusts that length. It reads past the end of the static buffer, through the rest of the session object and beyond, and copies those bytes into the blob it returns.
The output buffer is sized from the same length, so there is no overflow on the write side. The bytes end up in memory the application handles, for example a serialized session in an external cache. They are not sent to the attacker directly. The function belongs to the OpenSSL compatibility layer and is not part of a default build.
Affected Products and Versions
- Component:
src/ssl_sess.c,wolfSSL_i2d_SSL_SESSION(), exported to applications asi2d_SSL_SESSION(wolfssl/openssl/ssl.h:1326). - Required build:
OPENSSL_EXTRAandHAVE_SESSION_TICKET. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild enables neither the compatibility layer nor session tickets and does not include this code. - Other releases were not checked.
Technical Details
The ticket section of the serializer writes the length and then copies that many bytes (src/ssl_sess.c:2909-2911):
c16toa(sess->ticketLen, data + idx); idx += OPAQUE16_LEN;
XMEMCPY(data + idx, sess->ticket, sess->ticketLen);
idx += sess->ticketLen;
The blob size is computed from the same field (src/ssl_sess.c:2816). Nothing compares ticketLen with SESSION_TICKET_LEN or with ticketLenAlloc.
- A client session holds a ticket in a heap buffer, with
ticketLengreater thanSESSION_TICKET_LEN. - A later ticket installation fails to allocate. The failure paths in
wolfSSL_set_SessionTicket()(src/ssl_api_ext.c:1513-1517) andSetTicket()(src/internal.c:38845-38855) leaveticketpointing atstaticTicket(wolfssl/internal.h:5136) andticketLenAllocat zero.ticketLenkeeps the old, larger value. - The application calls
wolfSSL_i2d_SSL_SESSION()on that session. - The copy reads
ticketLenbytes fromstaticTicket. Everything after the firstSESSION_TICKET_LENbytes comes from the rest of the session object and from the heap after it. In the worst case the length is close to the 16-bit maximum. - The blob returned to the application contains those bytes.
Other code in the same file handles this state. SessionSanityPointerSet() clamps ticketLen to SESSION_TICKET_LEN when it points ticket at the static buffer (src/ssl_sess.c:393-399), and the cache restore failure path sets ticketLen to zero (src/ssl_sess.c:1463, src/ssl_sess.c:1474). The serializer has no equivalent check.
Reachability and Preconditions
- Build with
OPENSSL_EXTRAandHAVE_SESSION_TICKET. - The session must first reach the inconsistent state. That needs a ticket larger than the static buffer, followed by a failed allocation when another ticket is installed. A malicious server can issue large tickets, but the allocation failure depends on memory pressure in the client.
- The application then serializes that same session object.
- The serializer itself adds no input that an attacker controls.
Impact
Heap memory next to the session's static ticket buffer is copied into the serialized session. The amount is the stale length minus SESSION_TICKET_LEN. The data goes wherever the application sends serialized sessions, such as a shared or external session cache. An attacker does not receive it directly, which limits the practical consequence.
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 has two parts. The root cause is in the allocation-failure paths: whenever ticket is reset to the static buffer, ticketLen should be reset as well. As a second layer, wolfSSL_i2d_SSL_SESSION() should cap ticketLen at SESSION_TICKET_LEN when ticketLenAlloc is zero, as SessionSanityPointerSet() already does. A shared helper for all ticket readers would cover other consumers of the same state.
Applications can avoid the read by not serializing a session after a ticket operation on it has failed with a memory error.
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.