← ALL ADVISORIES

HIGH BYTERAY-2026-0302Disclosed

wolfSSL — Mismatched Free of a Static-Pool TLS 1.3 Ticket Nonce During Session Cache Eviction

In static-memory builds with WOLFSSL_TICKET_NONCE_MALLOC, a TLS 1.3 ticket nonce longer than the inline buffer is allocated from the connection's memory pool and stored in the session cache, which later frees it with a NULL heap hint. A server that sends a long nonce makes the client pass a pool-interior pointer to the system allocator when the entry is evicted.

Advisory
BYTERAY-2026-0302
CWE
CWE-762
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), TLS 1.3 clients built with WOLFSSL_STATIC_MEMORY and WOLFSSL_TICKET_NONCE_MALLOC that use session tickets and the internal session cache
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL allocations carry a heap hint. In a WOLFSSL_STATIC_MEMORY build the hint selects a fixed memory pool, and a NULL hint selects the system allocator or a global pool. A block has to be freed with the hint it was allocated with.

A TLS 1.3 client stores the nonce from a server's NewSessionTicket in its session. With WOLFSSL_TICKET_NONCE_MALLOC, a nonce longer than the inline buffer is allocated dynamically, from the session's hint. When the session is added to the internal cache, the nonce is copied into a block allocated with the same pool hint, and the cache entry's own hint is set to NULL. When the entry is later evicted, EvictSessionFromCache() frees the nonce with a NULL hint. The block came from the pool, so the free goes to the wrong allocator.

The nonce length is one byte chosen by the server. Eviction is routine cache housekeeping. The result is corruption of the client's allocator state and a block lost from a bounded pool. Default builds do not use static memory and do not define WOLFSSL_TICKET_NONCE_MALLOC.

Affected Products and Versions

  • Component: wolfSSL session cache, EvictSessionFromCache() and AddSessionToCache() in src/ssl_sess.c.
  • Required build: WOLFSSL_STATIC_MEMORY (--enable-staticmemory) with a pool hint in use on the connection, TLS 1.3, session tickets, the internal session cache, and WOLFSSL_TICKET_NONCE_MALLOC. The affected code is compiled out of FIPS builds older than version 5.3.
  • Role: a TLS 1.3 client that caches tickets issued by the server.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include this code.
  • Other releases were not checked.

Technical Details

The free is at src/ssl_sess.c:101, behind a check that the nonce is not the inline buffer (src/ssl_sess.c:98-99):

        if ((session->ticketNonce.data != NULL) &&
            (session->ticketNonce.data != session->ticketNonce.dataStatic))
        {
            XFREE(session->ticketNonce.data, NULL, DYNAMIC_TYPE_SESSION_TICK);
            session->ticketNonce.data = NULL;
        }

The hint is hard-coded to NULL. The block being freed was allocated with a pool hint:

  1. The server sends a NewSessionTicket. DoTls13NewSessionTicket() reads the one-byte nonce length (src/tls13.c:14488). Without WOLFSSL_TICKET_NONCE_MALLOC a length above MAX_TICKET_NONCE_STATIC_SZ (wolfssl/internal.h:1607) is rejected (src/tls13.c:14489-14496). With it, that check is not compiled.
  2. SessionTicketNoncePopulate(), called at src/tls13.c:14535, allocates the long nonce from session->heap, the pool hint (src/tls13.c:14417-14420).
  3. AddSession() calls AddSessionToCache(), which allocates a copy for the cache from addSession->heap, again the pool hint (src/ssl_sess.c:1946-1947). The comment there assumes the cache entry and the session being added share a heap.
  4. AddSessionToCache() sets cacheSession->heap = NULL (src/ssl_sess.c:2125) and then stores the pool block in cacheSession->ticketNonce.data (src/ssl_sess.c:2167-2172). Nothing records which allocator owns the nonce any more.
  5. The entry is evicted: when its slot is reused (src/ssl_sess.c:2066-2067), on a timeout flush (src/ssl_sess.c:919), by wolfSSL_CTX_remove_session() (src/ssl_sess.c:3458), or when the cache is freed at cleanup (src/ssl.c:3762, src/ssl.c:3768).
  6. EvictSessionFromCache() frees the nonce with a NULL hint. wolfSSL_Free() sends a NULL-hint free to the C library free() (wolfcrypt/src/memory.c:1261), or, when a global heap hint is set, links the block into that pool's free list (wolfcrypt/src/memory.c:1273).

The pointer handed to free() lies inside the application's static pool buffer and was never returned by malloc(). The pool that owns the block does not get it back.

Reachability and Preconditions

  • Build: WOLFSSL_STATIC_MEMORY, WOLFSSL_TICKET_NONCE_MALLOC, TLS 1.3 and session tickets, as listed above.
  • Runtime: the client loads a static memory pool for its context, uses the internal session cache, and keeps tickets it receives.
  • Attacker position: the TLS 1.3 server the client connects to, or a party able to act as one. It needs no more than a certificate the client already accepts.
  • Trigger: a NewSessionTicket whose nonce is longer than the inline buffer, followed by any eviction of that cache entry. No memory exhaustion or error path is involved.

Impact

A server can make the client free a pool block through the wrong allocator during ordinary cache housekeeping. With the system allocator this corrupts heap metadata or aborts the process, and each occurrence removes a block from the bounded pool, which leads to allocation failures over time. With a global heap hint the block joins the wrong pool's free list and can later be handed out while its original owner still treats it as its own, which is a path to further corruption and to disclosure of memory contents.

ByteRay built a TLS 1.3 client on a static memory pool with WOLFSSL_TICKET_NONCE_MALLOC under AddressSanitizer and connected it to a server that sent a NewSessionTicket with a 200-byte nonce. At cleanup the sanitizer reported a free of an address that was not allocated by malloc(), in EvictSessionFromCache() at src/ssl_sess.c:101, and placed the address inside the application's pool buffer; the same ticket with an 8-byte nonce ran without a report.

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 keep the allocating hint with the buffer. Either the cache entry stores the hint that owns its ticket nonce and every free of the nonce uses it, including src/ssl_sess.c:101 and the deferred free prepared at src/ssl_sess.c:2099-2107, or the cache's copy of the nonce is allocated with the same NULL hint that the eviction path frees it with. The assumption stated at src/ssl_sess.c:1943-1945 holds only for members allocated with a NULL hint.

Workaround: do not define WOLFSSL_TICKET_NONCE_MALLOC in static-memory builds. The client then rejects ticket nonces longer than the inline buffer, so a server that uses long nonces cannot issue it tickets. Turning off the client session cache also avoids the path, at the cost of resumption.

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.

References