← ALL ADVISORIES

LOW BYTERAY-2026-0428Patched

wolfSSL — Unsynchronized One-Time Flag in MAXQ10xx Public-Key Callback Setup

maxq10xx_SetupPkCallbacks() guards its work with a plain static int that is tested and set without a lock. Two threads that create their first WOLFSSL_CTX at the same time both pass the test. The same flag also stops every later context from receiving the MAXQ10xx callbacks.

Advisory
BYTERAY-2026-0428
CWE
CWE-412
CVSS
2.9 (CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with --with-maxq10xx (WOLFSSL_MAXQ1065 or WOLFSSL_MAXQ108X)
Fixed in
Master commit 1d16e4ad83ab529c1eb2307a9ad5994946c33a9f (PR 11658, merged 2026-10-07). Not in a wolfSSL stable release as of 2026-12-03.
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

In builds for the Maxim MAXQ1065 and MAXQ1080 secure elements, every new WOLFSSL_CTX is passed to maxq10xx_SetupPkCallbacks(). The function installs the MAXQ10xx public-key and record-processing callbacks on that context. It is guarded by a file-scope static int, init_pk_callbacks, that is read on entry and written at the end, with no lock and no atomic access.

Two threads that each create a context before either has finished the function both see the flag at zero and both run the body. That is a data race on the flag. Its practical effect is small: each thread installs callbacks on its own context, and the one piece of shared state written in the body, tls13active, is set to the same value by both.

The flag is also the wrong tool for the job. The callbacks are stored per context, so a process-wide run-once guard means that only the first context ever created receives them. wolfSSL removed the flag on master for that reason. No attacker input is involved, and a default ./configure build does not compile this code.

Affected Products and Versions

  • Component: MAXQ10xx port, maxq10xx_SetupPkCallbacks() in wolfcrypt/src/port/maxim/maxq10xx.c.
  • Required build: --with-maxq10xx=MAXQ1065 or --with-maxq10xx=MAXQ108x (configure.ac:3678-3704), which defines WOLFSSL_MAXQ10XX_TLS (wolfssl/wolfcrypt/settings.h:2524-2542). The vendor SDK library is needed to link.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same flag, test and store. Fixed on master by commit 1d16e4ad83ab529c1eb2307a9ad5994946c33a9f (PR 11658); no release contains the fix.
  • A default ./configure build does not include this code. Earlier releases were not checked.

Technical Details

The flag is a file-scope static int init_pk_callbacks = 0; (wolfcrypt/src/port/maxim/maxq10xx.c:175). The function tests it at wolfcrypt/src/port/maxim/maxq10xx.c:3846-3848:

    if (init_pk_callbacks) {
        return;
    }

and sets it as its last statement, at wolfcrypt/src/port/maxim/maxq10xx.c:3885. Between the two, the body calls the wolfSSL_CTX_Set*Cb() family on the context it was given. Each of those stores a function pointer in that context, for example ctx->EccSignCb at src/ssl_api_pk.c:855-860. On MAXQ108X builds with a TLS 1.3 method the body also writes the file-scope variable tls13active (wolfcrypt/src/port/maxim/maxq10xx.c:3857, declared at wolfcrypt/src/port/maxim/maxq10xx.c:106).

The caller is the context initialisation path, at src/internal.c:3037-3041:

#ifdef WOLFSSL_MAXQ10XX_TLS
    /* Let maxq10xx know what TLS version we are using. */
    ctx->devId = MAXQ_DEVICE_ID;
    maxq10xx_SetupPkCallbacks(ctx, &method->version);
#endif /* WOLFSSL_MAXQ10XX_TLS */

No lock is held there. The sequence that races:

  1. Thread A creates a context, reads init_pk_callbacks as 0 and enters the body.
  2. Thread B creates another context and reads the flag as 0 before A reaches the store.
  3. Both threads install callbacks on their own contexts. On a MAXQ108X TLS 1.3 build both write 1 to tls13active.
  4. Both write 1 to init_pk_callbacks.

The read and write of a plain int from two threads without synchronization is undefined by the C standard. In this function the racing body touches only per-context fields and same-value stores, so the visible outcome is that both contexts are set up.

The outcome without a race is the more significant one. After the first context, the test at line 3846 returns early for every other context in the process. Those contexts keep devId set to the MAXQ10xx device but have none of the callbacks installed. tls13active is written only at line 3857, so it is set only if the first context created was a TLS 1.3 one; the MAXQ108X handlers that test it, such as wolfcrypt/src/port/maxim/maxq10xx.c:1719, depend on that.

Reachability and Preconditions

  • The build is a MAXQ10xx build as listed above. These builds are client-only (wolfssl/wolfcrypt/settings.h:2530-2531).
  • For the race: two threads call wolfSSL_CTX_new() at the same time, and neither call has been preceded by a completed one in the process.
  • For the early return: the application creates more than one WOLFSSL_CTX.
  • The trigger is the application's own context creation. No network input, authentication state or user interaction is involved, and neither a remote nor a local attacker controls the timing.

Impact

Confirmed from source: the flag is read and written without synchronization on the context creation path, and two concurrent first calls both run the body. Also confirmed: with the flag in place, only the first context in a process receives the MAXQ10xx callbacks.

Not supported by the source: a handshake failure caused by the race itself. The racing store to tls13active writes the value it already has or is about to get, and a TLS 1.3 context whose own setup runs the body has written it before that context is used. A stale read of that variable that selects the wrong handler and fails a handshake was considered, and no path to it was found.

There is no memory-safety effect and no effect on confidentiality or integrity. The issue is a robustness defect in a non-default hardware port.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

Fixed on master by commit 1d16e4ad83ab529c1eb2307a9ad5994946c33a9f (PR 11658, merged 2026-10-07). The commit deletes init_pk_callbacks, its test and its store, so the callbacks are installed on every context and there is no flag left to race on. The store to tls13active is still an unsynchronized write of a constant. The fix is on master only. No release contains it as of 2026-12-03.

Until a release does, MAXQ10xx applications should create their WOLFSSL_CTX objects from one thread before starting others, and should be aware that on affected versions only the first context has the MAXQ10xx callbacks. Applying the upstream commit removes both conditions.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-10-06 — Pull request 11658 opened upstream.
  • 2026-10-07 — Pull request 11658 merged to master.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References