← ALL ADVISORIES

HIGH BYTERAY-2026-0305Disclosed

wolfSSL — Out-of-Bounds Write in Session ID Setters on Client Session Cache References

On a TLS client, wolfSSL_get_session() returns a 12-byte cache locator cast to WOLFSSL_SESSION. wolfSSL_SESSION_set1_id() and wolfSSL_SESSION_set1_id_context() write through that pointer as if it were a full session, placing up to 32 caller-supplied bytes about 100 bytes past the locator in the global client session cache.

Advisory
BYTERAY-2026-0305
CWE
CWE-375
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), client applications on builds with OPENSSL_ALL, WOLFSSL_HAPROXY or WOLFSSL_NGINX and without NO_SESSION_CACHE_REF
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

On the client side, wolfSSL_get_session() does not return a session object. For backward compatibility it returns a persistent reference into the client session cache: a pointer to a ClientSession, a 12-byte locator, cast to WOLFSSL_SESSION*. The library expects every function that receives such a pointer to convert it to the real cache entry with ClientSessionToSession() before it touches any member.

Two functions of the OpenSSL compatibility layer do not make that conversion. wolfSSL_SESSION_set1_id() and wolfSSL_SESSION_set1_id_context() store a length and copy an identifier into fields of WOLFSSL_SESSION. When the pointer is a locator, those fields lie well outside the 12-byte object.

The writes land in the static global client cache, in neighbouring locators, or past the end of the array for an entry in the last row. The bytes are the identifier the application passes in. In a resumption flow that is normally the session ID chosen by the server. Default builds do not compile the two setters and are not affected.

Affected Products and Versions

  • Component: src/ssl_sess.c. The pointer comes from wolfSSL_get_session(). The writes are in wolfSSL_SESSION_set1_id() and wolfSSL_SESSION_set1_id_context().
  • Required build: OPENSSL_ALL, WOLFSSL_HAPROXY or WOLFSSL_NGINX (src/ssl_sess.c:4415), that is --enable-opensslall, --enable-haproxy or --enable-nginx. The client cache reference is in use unless NO_SESSION_CACHE_REF is defined.
  • Required usage: a client application calls SSL_SESSION_set1_id or SSL_SESSION_set1_id_context on a pointer obtained from wolfSSL_get_session() for a client connection.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include the two setters.
  • Other releases were not checked.

Technical Details

The client branch of wolfSSL_get_session() returns the locator (src/ssl_sess.c:119-121):

            if (ssl->clientSession) {
                return (WOLFSSL_SESSION*)ssl->clientSession;
            }

ssl->clientSession is a ClientSession* (wolfssl/internal.h:6704). The structure holds a row, an index, a hash of the session ID and a generation counter, 12 bytes in all (wolfssl/ssl_sess.h:145-152). A comment in the session code states the rule that goes with it: functions that use WOLFSSL_SESSION members must first pass the pointer through ClientSessionToSession() (src/ssl_sess.c:1780-1789). That function checks whether the pointer lies inside the global ClientCache and, if so, resolves it to the session it refers to.

wolfSSL_SESSION_set1_id() checks for NULL and for a length above ID_LEN, and then writes (src/ssl_sess.c:4431-4433):

    s->sessionIDSz = (byte)sid_len;
    if (sid != s->sessionID) {
        XMEMCPY(s->sessionID, sid, sid_len);
    }

wolfSSL_SESSION_set1_id_context() does the same with sessionCtxSz and sessionCtx (src/ssl_sess.c:4447-4449). Neither calls the resolver.

  1. A client connection completes. The application calls wolfSSL_get_session() and receives the locator cast to a session pointer.
  2. The application calls SSL_SESSION_set1_id or SSL_SESSION_set1_id_context on it. The OpenSSL names map to the wolfSSL functions at wolfssl/openssl/ssl.h:469-470.
  3. The setter writes the one-byte length field, compares the caller's pointer with the address of the identifier field, and copies up to 32 bytes into that field.
  4. sessionID is declared far beyond offset 12 in WOLFSSL_SESSION (wolfssl/internal.h:5092). The writes fall roughly 100 bytes past the locator, inside the ClientCache array or beyond its end.

Reachability and Preconditions

  • Build: one of the compatibility options above. NO_SESSION_CACHE_REF not defined, and the client cache not disabled with NO_CLIENT_CACHE.
  • The application is a TLS client and calls one of the two setters on the result of wolfSSL_get_session(). An application that never calls them is not affected. wolfSSL_get1_session() returns ssl->session, a real session object (src/ssl_sess.c:156-171), and the setters stay inside it.
  • Attacker position: the TLS server the client connects to, or a party able to act as it. That party influences the bytes only as far as the application passes peer-chosen data, such as the server's session ID, to the setter.
  • No memory-layout knowledge is needed for the write to occur. Which cache slot the locator occupies depends on the server ID hash and on how many sessions the row already holds.

Impact

An out-of-bounds write of one length byte and up to 32 identifier bytes into process-wide state. Inside the array the write overwrites other connections' locators, so later resumption attempts for unrelated servers can fail or resolve to the wrong entry. For a locator near the end of the last row the write leaves the ClientCache object and reaches whatever the linker placed after it. The report also notes that freeing such a pointer with wolfSSL_SESSION_free() resolves it to the shared cache entry and clears that entry's master secret and session ID in place.

ByteRay reproduced the write on a TLS 1.2 client built with --enable-opensslextra --enable-opensslall under AddressSanitizer and UndefinedBehaviorSanitizer. With a server ID that hashes to the last cache row and the row filled by repeated handshakes, the locator returned by wolfSSL_get_session() occupied the last 12 bytes of the cache. wolfSSL_SESSION_set1_id() then produced a global-buffer-overflow write at src/ssl_sess.c:4431, about 104 bytes past the end of the global, and wolfSSL_SESSION_set1_id_context() did the same at src/ssl_sess.c:4447. Reading the session ID through an accessor that resolves the pointer 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 for both setters to pass the pointer through ClientSessionToSession() before they touch any member, as wolfSSL_SESSION_free() and the other session accessors do, and to return failure when the pointer does not resolve to a session. That removes the out-of-bounds compare and both copies. A broader change is for the client side of wolfSSL_get_session() to stop returning a cache locator, and for every public session function to be checked for direct member access on caller-provided pointers.

Workarounds:

  • Build with NO_SESSION_CACHE_REF. wolfSSL_get_session() then returns ssl->session (src/ssl_sess.c:112-113).
  • Or, in the application, use wolfSSL_get1_session() and call the setters on that object only.

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