wolfSSL — Stale Session Ticket Length After Allocation Failure in Client Session Ticket Storage
When replacing a heap-allocated session ticket fails to allocate, wolfSSL_set_SessionTicket and SetTicket point the session back at its small static ticket buffer but keep the length of the released ticket. Later code trusts that length: a resumption ClientHello sends bytes from beyond the static buffer to the peer, and a later ticket copy can write past it.
- Advisory
- BYTERAY-2026-0367
- CWE
- CWE-672
- CVSS
- 5.9 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/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), builds with HAVE_SESSION_TICKET, clients that hold a session ticket larger than the static ticket buffer
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
A wolfSSL client keeps the session ticket it received in the WOLFSSL_SESSION object. Tickets up to SESSION_TICKET_LEN bytes use a static buffer inside the object. Larger tickets use a separate heap allocation. ticketLen records the ticket size and ticketLenAlloc records whether the ticket pointer refers to heap memory.
Both functions that install a ticket release the old heap buffer before they allocate the new one. If that allocation fails, they fall back to the static buffer and clear ticketLenAlloc, but they do not reset ticketLen. The session is left with a pointer to the static buffer and the length of the larger ticket that was just released.
Code that later uses that session reads or writes past the static buffer. A resumption ClientHello copies ticketLen bytes into its session ticket extension and sends adjacent heap memory to the server. A later wolfSSL_set_SessionTicket() call with a size between the static buffer size and the stale length copies that many bytes into the static buffer. Reaching the state needs an allocation failure at this point and reuse of the same session object. Session tickets are off in a default build.
Affected Products and Versions
- Component:
src/ssl_api_ext.c,wolfSSL_set_SessionTicket(), andsrc/internal.c,SetTicket(). - Required build:
HAVE_SESSION_TICKET(--enable-session-ticket).SetTicket()is reached from the client's NewSessionTicket handling. WithHAVE_SECRET_CALLBACK,wolfSSL_set_SessionTicket()is also reached fromDoClientTicket()(src/internal.c:44230). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not enable session tickets (configure.ac:9469-9483) and does not include this code. - Other releases were not checked.
Technical Details
wolfSSL_set_SessionTicket() frees the old heap ticket and allocates a new buffer when ticketLen is smaller than the new size (src/ssl_api_ext.c:1506-1512). The failure branch restores the pointer and the allocation size only (src/ssl_api_ext.c:1513-1517):
if (ssl->session->ticket == NULL) {
ssl->session->ticket = ssl->session->staticTicket;
ssl->session->ticketLenAlloc = 0;
ret = MEMORY_ERROR;
}
ticketLen is assigned only on success (src/ssl_api_ext.c:1530). SetTicket() has the same order: it frees the heap ticket and resets the pointer (src/internal.c:38845-38849), and returns MEMORY_E when the new allocation fails (src/internal.c:38855), before ticketLen is updated (src/internal.c:38859).
- The session holds a heap ticket, so
ticketLenis greater thanSESSION_TICKET_LEN. - A new ticket arrives. On the client this is the server's NewSessionTicket message, which
DoSessionTicket()passes toSetTicket()(src/internal.c:38931-38938). - The old buffer is freed and the new allocation fails.
ticketpoints atstaticTicket(wolfssl/internal.h:5136),ticketLenAllocis zero, andticketLenis unchanged. - Read:
SendClientHello()builds the session ticket extension withTLSX_SessionTicket_Create(0, ssl->session->ticket, ssl->session->ticketLen, ...)(src/internal.c:34809). The bytes past the static buffer go on the wire.wolfSSL_get_SessionTicket()copies the same range to the caller (src/ssl_api_ext.c:1465-1467). - Write: a later
wolfSSL_set_SessionTicket()call withbufSzaboveSESSION_TICKET_LENand not above the staleticketLenskips reallocation, because the test atsrc/ssl_api_ext.c:1506is false. The copy atsrc/ssl_api_ext.c:1525writesbufSzbytes into the static buffer and overruns the fields that follow it in the session object.
The session cache restore path sets ticketLen to zero when it fails (src/ssl_sess.c:1454-1479), so a duplicated session does not carry the stale length. Only the original session object does.
Reachability and Preconditions
- Build with
HAVE_SESSION_TICKET. The affected endpoint is a TLS client. - The session already holds a ticket larger than the static buffer. The server chooses the ticket size.
- A heap allocation fails while that ticket is being replaced. A malicious server can issue many large tickets to add memory pressure, but the failure is not deterministic.
- The same session object is used afterwards, for a resumption attempt or for another ticket call.
- No authentication beyond acting as the TLS server is needed to supply tickets.
Impact
On a resumption attempt the client sends heap memory that follows the static ticket buffer to the server it connects to. The amount is the stale length minus SESSION_TICKET_LEN. Separately, a later ticket installation of a suitable size writes past the static buffer inside the heap-allocated session object. Both depend on a transient allocation failure, so the outcome is not reliable for an attacker.
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 make ticketLen always describe the live buffer. Both failure branches should set it to zero when they fall back to the static buffer, as the cache restore path does. Tracking buffer capacity separately from ticket length would stop the size test in wolfSSL_set_SessionTicket() from being satisfied by a stale length. As a second layer, readers and the copy can clamp the length to SESSION_TICKET_LEN when ticketLenAlloc is zero. BYTERAY-2026-0442 covers another reader of the same state. Applications can reduce exposure by discarding a session, instead of reusing it for resumption, after a ticket call or handshake on it fails with a memory error. Builds without session tickets 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.