← ALL ADVISORIES

LOW BYTERAY-2026-0484Disclosed

wolfSSL — Race Condition and Use-After-Free on Global Session Ex-Data Callback Context

The callback context for TLS session ex-data is a non-static global pointer that is set, freed and dereferenced without any lock. If library teardown or a second registration runs while another thread creates, duplicates or frees a session, that thread can call function pointers read from freed memory.

Advisory
BYTERAY-2026-0484
CWE
CWE-500
CVSS
3.9 (CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:L/I:L/A:L)
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_EX_DATA_CRYPTO, which OPENSSL_ALL and several application compatibility options define automatically
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL's OpenSSL compatibility layer lets an application attach extra data to session objects and register callbacks that run when that data is created, duplicated or freed. The bookkeeping for those callbacks is kept in one process-wide pointer, crypto_ex_cb_ctx_session.

The pointer is defined without static, so any translation unit in the build can read, overwrite or free it. No operation on it is serialized. It is set during ex-data registration, freed and set to NULL during library teardown without a lock, and dereferenced without a lock on ordinary session paths.

If teardown runs while another thread is creating or duplicating a session, that thread can follow callback function pointers from memory that has been freed. Triggering this requires the application to tear the library down, or register callbacks again, while sessions are in use. It is an in-process concurrency hazard and has no remote trigger. The code is compiled only with HAVE_EX_DATA_CRYPTO, which is not part of a default build.

Affected Products and Versions

  • Component: src/ssl.c (definition, registration, teardown) and src/ssl_sess.c (session paths).
  • Required build: HAVE_EX_DATA_CRYPTO. It is defined automatically for OPENSSL_ALL and for the wpa_supplicant, stunnel, nginx, lighttpd, HAProxy, OpenSSH, SFCB and wolfSentry-hooks compatibility options (wolfssl/wolfcrypt/settings.h:5052-5059).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not define HAVE_EX_DATA_CRYPTO.
  • Other releases were not checked.

Technical Details

The pointer is defined at src/ssl.c:8323 as CRYPTO_EX_cb_ctx* crypto_ex_cb_ctx_session = NULL;. The declaration in wolfssl/internal.h:8081 carries a visibility attribute, which limits what the installed library exports. It does not stop other translation units in the same build from binding to the symbol. The test suite does so and frees the context directly (tests/api/test_session.c:1607-1608).

Lifecycle, none of it under a lock:

  1. Set: registration of session ex-data callbacks passes the address of the pointer to crypto_ex_cb_new() (src/ssl.c:8434).
  2. Freed: teardown frees the context and assigns NULL (src/ssl.c:3826-3829):
#ifdef HAVE_EX_DATA_CRYPTO
    crypto_ex_cb_free(crypto_ex_cb_ctx_session);
    crypto_ex_cb_ctx_session = NULL;
#endif
  1. Used: session creation checks the pointer for NULL and then passes it to the setup function (src/ssl_sess.c:3926-3929). Session duplication passes it to crypto_ex_cb_dup_data() (src/ssl_sess.c:4227-4228). The session cache and free paths pass it to crypto_ex_cb_free_data() (src/ssl_sess.c:2060, src/ssl_sess.c:4311).

The check in step 3 and the use that follows are separate reads of a global. A free between them, or just before them, leaves the session path walking a freed list of callback entries.

Reachability and Preconditions

  • Build with HAVE_EX_DATA_CRYPTO, and the application registered session ex-data callbacks.
  • A multi-threaded application in which library teardown, a second registration, or other code that frees the context runs concurrently with session creation, duplication or release.
  • The race is driven by the application's own threads. A remote peer cannot cause the teardown.

Impact

A thread on a session path can read callback pointers from freed memory and call them. The likely outcome is a crash during shutdown or re-initialization. Because the freed memory holds function pointers, control-flow corruption is possible in principle if the memory has been reused. Both depend on the application racing teardown against live sessions.

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 the pointer static in src/ssl.c and reach it only through accessors that serialize access, with registration, teardown and the session paths under the same lock that protects the library's initialization reference count. Reference-counted ownership of the context, or attaching it to each WOLFSSL_CTX, are alternatives.

Applications should not call wolfSSL_Cleanup() while any thread still creates, copies or frees sessions, and should register session ex-data callbacks once, before starting worker threads.

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