wolfSSL — Unsynchronized One-Time Flag in the MAX3266X TRNG Seed Path
The MAX3266X wc_GenerateSeed() records that the TRNG health test has passed in a plain static int, read before the hardware RNG mutex is taken and written after it is released. Threads that seed for the first time together each run the health test. The test itself stays serialized.
- Advisory
- BYTERAY-2026-0430
- 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 for the MAX3266X port with MAX3266X_RNG (WOLFSSL_MAX3266X or WOLFSSL_MAX3266X_OLD) in a multi-threaded configuration
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
On the Maxim MAX3266X port, wolfCrypt takes its seed from the device's hardware TRNG. Before the first seed, wc_GenerateSeed() runs the TRNG health test once and remembers the result in a function-local static int, initDone.
The flag is read with no lock held. The health test runs under the hardware RNG mutex. The flag is then set after the mutex has been released. A second thread that enters the function before the store sees zero and runs the health test again.
The consequence is a repeated health test and nothing more. Each run holds the mutex, so the TRNG is never used by two threads at once, and a failed test is still reported to the caller. The unsynchronized read and write of the flag is a data race in the language sense. ByteRay found no path from it to a failed, weakened or predictable seed. The issue is published as a low-severity robustness defect. A default ./configure build does not compile this code.
Affected Products and Versions
- Component: wolfCrypt RNG seed source, the
MAX3266X_RNGvariant ofwc_GenerateSeed()inwolfcrypt/src/random.c. - Required build: the MAX3266X port (
WOLFSSL_MAX3266XorWOLFSSL_MAX3266X_OLD) withMAX3266X_RNG, which the port header turns on when no individual feature is selected (wolfssl/wolfcrypt/port/maxim/max3266x.h:45-49), and a multi-threaded configuration. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same function with the same flag. - Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03). The function there is unchanged.
- A default
./configurebuild does not include this code. Earlier releases were not checked.
Technical Details
The function, at wolfcrypt/src/random.c:9553-9575. The flag and its test:
static int initDone = 0;
(void)os;
if (initDone == 0) {
status = wolfSSL_HwRngMutexLock();
and the end of the guarded block, at wolfcrypt/src/random.c:9571-9574:
wolfSSL_HwRngMutexUnLock();
initDone = 1;
}
return wc_MXC_TRNG_Random(output, sz);
The test at line 9559 is outside the mutex. The health test at line 9564 is inside it. The store at line 9572 is outside it again. The sequence that repeats the test:
- Thread A reads
initDoneas 0, takes the mutex at line 9560, runsMXC_TRNG_HealthTest()and releases the mutex at line 9571. - Thread B reads
initDoneas 0 at any point before A executes line 9572. B may already be waiting on the mutex. - B takes the mutex and runs the health test a second time.
- Both threads set the flag and go on to
wc_MXC_TRNG_Random().
wc_MXC_TRNG_Random() takes the same mutex around the TRNG read (wolfcrypt/src/port/maxim/max3266x.c:618-645), so the health test and the read never overlap. If the health test fails, the function releases the mutex and returns WC_HW_E without setting the flag (wolfcrypt/src/random.c:9564-9570), so the next call tests again. That behaviour is correct and is not changed by the race.
The read at line 9559 and the write at line 9572 are accesses to a plain int from different threads with no synchronization between them. The C standard leaves that undefined. Both writers store the same value.
The mutex named here is the RNG hardware mutex. With WOLFSSL_ALGO_HW_MUTEX it is a separate per-algorithm mutex; without it, the name is a macro for the generic hardware crypto mutex (wolfssl/wolfcrypt/wc_port.h:1072-1083). The lazy initialization of those mutexes has unsynchronized flags of its own. See BYTERAY-2026-0354 for the per-algorithm mutexes and BYTERAY-2026-0357 for the generic one. This advisory covers only initDone.
Reachability and Preconditions
- The build is a MAX3266X build with the hardware TRNG as the seed source, as listed above.
- Two or more threads call into the seed path, for example through
wc_InitRng(), before any thread has completed a first seed. - The window exists once per boot.
- No network input, authentication state or user interaction is involved. An attacker has no control over the timing and gains nothing from it.
Impact
Confirmed from source: the health test can run more than once when several threads seed for the first time together. Each run is serialized by the hardware RNG mutex. The cost is the time of the extra test.
Not found: any effect on the seed. The TRNG read happens under the mutex after a health test that passed in the same thread. A failed test is returned as an error whether or not another thread raced. There is no memory-safety effect and no effect on confidentiality or integrity. The source review supports no availability effect beyond start-up latency.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03).
The fix direction is to set the flag before the mutex is released and to test it again once the mutex is held, so that a thread that waited for the mutex does not repeat the test. The flag should be an atomic type if the unlocked first test is kept.
Applications can avoid the window by making the first RNG call, for example wc_InitRng(), from one thread before starting others. No other action is needed.
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.