wolfSSL — Unsynchronized Initialization Flag in the nRF5x CryptoCell RNG Helper
nrf_random_generate() initializes the Nordic RNG driver once, guarded by a plain static int that is tested and set without a lock. Two threads that request random data for the first time together both call the driver's init, and the call that is refused returns an RNG error to its caller.
- Advisory
- BYTERAY-2026-0429
- 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 WOLFSSL_CRYPTOCELL and WOLFSSL_nRF5x_SDK_15_2 that use nrf_random_generate() as the RNG source from more than one thread
- Fixed in
- Master commit d1f97f90d01867bae5f65d22592aa6619fcf2788 (PR 11789, merged 2026-10-26). Not in a wolfSSL stable release as of 2026-12-03.
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The ARM CryptoCell 310 port for the Nordic nRF5 SDK contains a helper, nrf_random_generate(), that fills a buffer from the Nordic RNG driver. On its first call it initializes the driver and records that in a function-local static int. The test of the flag and the store to it are separate, unprotected steps.
If two threads make their first call at the same time, both read the flag as zero and both call nrf_drv_rng_init(). The helper treats every result other than NRF_SUCCESS as fatal, so the thread whose init call is refused returns -1. When the helper is wired in as wolfCrypt's block generator, that becomes a failed wc_RNG_GenerateBlock() for that one call. The flag is set by the other thread, so later calls succeed.
Exposure is narrow. Nothing in the wolfSSL tree calls the helper; the only reference is a commented-out line in the example configuration, and that configuration is single-threaded. An integrator has to select the helper as the RNG source and run a multi-threaded build to reach the race. No attacker input is involved.
Affected Products and Versions
- Component: ARM CryptoCell port,
nrf_random_generate()inwolfcrypt/src/port/arm/cryptoCell.c. - Required build:
WOLFSSL_CRYPTOCELLandWOLFSSL_nRF5x_SDK_15_2defined,NO_CRYPT_BENCHMARKnot defined (the guard that opens atwolfcrypt/src/port/arm/cryptoCell.c:239), a multi-threaded configuration, andCUSTOM_RAND_GENERATE_BLOCKset tonrf_random_generateby the integrator. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same function. - Removed on master: commit d1f97f90d01867bae5f65d22592aa6619fcf2788 (PR 11789) deletes the direct CryptoCell 310 port, including this file. No release contains that change.
- A default
./configurebuild does not include this code. The in-tree example configuration definesSINGLE_THREADED(IDE/CRYPTOCELL/user_settings.h:56-57) and selects a different generator (IDE/CRYPTOCELL/user_settings.h:469-470). Earlier releases were not checked.
Technical Details
The start of the helper (wolfcrypt/src/port/arm/cryptoCell.c:314-329), from line 317:
static int initialized = 0;
/* RNG must be initialized once */
if (!initialized) {
err_code = nrf_drv_rng_init(NULL);
if (err_code != NRF_SUCCESS) {
return -1;
}
initialized = 1;
}
The flag is tested at line 320 and stored at line 325. Nothing orders those two steps between threads:
- Thread A reads
initializedas 0 and callsnrf_drv_rng_init(NULL). - Thread B reads
initializedas 0 before A reaches line 325 and makes the same call. - One of the two calls is made on a driver that is already initialized.
- The thread that receives a result other than
NRF_SUCCESSreturns -1 at lines 322-324 without producing output. The other thread sets the flag and continues.
nrf_drv_rng_init() belongs to the Nordic SDK, which is not part of the wolfSSL tree. That it reports an error on a repeated init is visible from wolfSSL's other callers. The nRF51 and nRF5x seed function accepts NRF_ERROR_INVALID_STATE and NRF_ERROR_MODULE_ALREADY_INITIALIZED from the same call as "already running" (wolfcrypt/src/random.c:8695-8705), and so does the nRF51 port (wolfcrypt/src/port/nrf51.c:74-77). nrf_random_generate() has no such tolerance.
When CUSTOM_RAND_GENERATE_BLOCK names the helper, wc_RNG_GenerateBlock() calls it directly and returns its result (wolfcrypt/src/random.c:5665-5667). The buffer has been zeroed before the call, and the caller receives a non-zero return code.
The helper has no prototype in the port's header and no caller in the tree. The same guard also contains a second function-local flag, in current_time(), which only protects a benchmark timer.
Reachability and Preconditions
- The build is a direct CryptoCell 310 build for the nRF5 SDK, as listed above.
- The integrator has declared
nrf_random_generate()and selected it withCUSTOM_RAND_GENERATE_BLOCK. The example configuration selectscc310_random_generateinstead. - The build is multi-threaded, and two threads make their first RNG request before either has finished the driver init.
- The window exists once per boot, at first use.
- No network input, authentication state or user interaction is involved. An attacker has no direct control over the timing.
Impact
Confirmed from source: the one-time init is not serialized, and a non-success result from the driver's init is returned to the caller as an RNG failure. Under the race, one RNG request fails. The failure is reported to the caller; no weak or predictable output is returned as if it were valid. Callers that check the return code see one failed operation, for example one failed key generation or handshake. A caller that ignores the return code would use the zeroed buffer, which is a defect in that caller.
The failure does not persist. The next call finds the flag set. There is no memory-safety effect.
Not verified: the exact code the Nordic driver returns on a concurrent or repeated init. This is inferred from the in-tree callers cited above.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
wolfSSL master no longer contains the code. Commit d1f97f90d01867bae5f65d22592aa6619fcf2788 (PR 11789, merged 2026-10-26) removes the direct CryptoCell 310 backend, and a build that defines WOLFSSL_CRYPTOCELL or WOLFSSL_nRF5x_SDK_15_2 now stops with a compile-time error. The pull request describes a removal of the backend and does not mention this issue. No release contains the removal as of 2026-12-03.
For releases that still carry the port:
- Make the first RNG request, for example
wc_InitRng(), from one thread before starting others. - Or keep the port's default generator,
cc310_random_generate, which the example configuration uses. - If the helper is kept in a local tree, treat the driver's "already initialized" results as success, as
wolfcrypt/src/random.c:8695-8705does, and serialize the first call.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-10-16 — Pull request 11789, which removes the direct CryptoCell 310 port, opened upstream.
- 2026-10-26 — Pull request 11789 merged to master.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.
References
cryptoCell.cat the tested commit;nrf_random_generateis at lines 314 to 329- The nRF5x seed function that tolerates a repeated init
- PR 11789
- Commit d1f97f9, removal of the port
- BYTERAY-2026-0430, the same flag pattern in the MAX3266X seed path
- BYTERAY-2026-0357, the same flag pattern on the hardware crypto mutex
- CWE-412