wolfSSL — Unchecked Entropy Provider Result in IDIRECT_DEV_RANDOM Seed Generation
The IDIRECT_DEV_RANDOM seed function calls the platform getRandom provider, stores its return value in a variable that is never read, and returns 0. If the provider fails or returns fewer bytes than requested, the Hash_DRBG is seeded from whatever the buffer already held.
- Advisory
- BYTERAY-2026-0398
- CWE
- CWE-1213
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds that define IDIRECT_DEV_RANDOM and map its GenerateSeed function to wc_GenerateSeed
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
For the IDIRECT_DEV_RANDOM platform, the seed function in wolfcrypt/src/random.c collects entropy by calling the platform's getRandom() provider. It ignores the outcome. The number of bytes returned is stored in a variable that is never read, and the function always returns 0.
Every caller on the seeding path decides whether seeding worked by checking that return value. If getRandom() fails or fills only part of the buffer, wolfSSL treats the buffer's existing contents, uninitialized stack memory or stale data, as a full-entropy seed and builds the Hash_DRBG state from it. On embedded targets stale stack contents are often the same across reboots, so DRBG state and the TLS keying material derived from it can repeat.
The code is compiled only in integrator builds that define IDIRECT_DEV_RANDOM and also map the local GenerateSeed symbol to wc_GenerateSeed outside the tree. Default builds are not affected.
Affected Products and Versions
- Component:
wolfcrypt/src/random.c,GenerateSeed()in theIDIRECT_DEV_RANDOMbranch (wolfcrypt/src/random.c:8828-8839). - Required build:
IDIRECT_DEV_RANDOM, plus an out-of-tree mapping fromGenerateSeedtowc_GenerateSeed. The tree declares and calls onlywc_GenerateSeed(wolfssl/wolfcrypt/random.h:682), so the macro alone does not produce a linkable build. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The option is documented as off by default (
wolfcrypt/src/random.c:73). A default build is not affected. - Other releases were not checked.
Technical Details
The whole function is:
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
int num_bytes_returned = 0;
num_bytes_returned = getRandom( (int) sz, (unsigned char *) output );
return 0;
}
- A caller on the seeding path requests
szbytes of seed. The callers are DRBG instantiation in_InitRng()(wolfcrypt/src/random.c:3135),PollAndReSeed()(wolfcrypt/src/random.c:4685) and the nonce reseed helper (wolfcrypt/src/random.c:5125). getRandom()fails or writes fewer thanszbytes. Its return value is assigned tonum_bytes_returnedand not used.- The function returns 0 (
wolfcrypt/src/random.c:8838). Each caller treats only a non-zero return as failure (wolfcrypt/src/random.c:3144,wolfcrypt/src/random.c:4687,wolfcrypt/src/random.c:5126), so all of them continue. - The seed buffer keeps what it held before the call. In
PollAndReSeed()without the small-stack options that is the uninitialized stack arraynewSeed(wolfcrypt/src/random.c:4666). On a short fill the remainder is stale memory. - The Hash_DRBG is instantiated or reseeded from that buffer.
The seed health tests in wc_RNG_TestSeed() look for patterns inside one buffer. They do not detect a buffer that repeats across calls or across boots.
Reachability and Preconditions
- Build:
IDIRECT_DEV_RANDOMand the out-of-tree symbol mapping described above. - The platform
getRandom()must fail or short-fill at run time. While it fills the full request, the seed is as good as the provider. - No attacker input is needed to reach the seed path. It runs at RNG initialization and at every reseed. Whether an attacker can cause the provider to fail depends on the platform.
- To use the result, the attacker must be able to guess or reproduce the stale buffer contents, for example because they repeat on every boot of the same firmware.
Impact
A failed or partial entropy read is accepted as a valid seed. The DRBG state is then derived from predictable or repeating memory, and so is everything drawn from it: TLS randoms, ephemeral keys, nonces and session-ticket material. An attacker who can reproduce the seed can reproduce that output. The condition arises only on the gated platform build and only when the provider misbehaves.
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 branch fail closed: compare the value returned by getRandom() with the requested size and return a non-zero error on failure or short fill, or retry until the request is satisfied. The buffer's prior contents and a zero fill are both unsafe fallbacks. An in-tree mapping of GenerateSeed to wc_GenerateSeed for this platform would remove the need for out-of-tree glue. Integrators on this platform can supply their own wc_GenerateSeed that checks the provider result.
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.