wolfSSL — Unbounded Data-Ready Wait in STM32 Standard Peripheral Library Seed Generation
The STM32 Standard Peripheral Library branch of wc_GenerateSeed polls the RNG data-ready flag with no timeout. If the peripheral latches a seed or clock error while the buffer is being filled, the loop never exits and the function hangs while holding the crypto hardware mutex. The bare-metal branch of the same function bounds this wait.
- Advisory
- BYTERAY-2026-0529
- CWE
- CWE-1213
- CVSS
- 3.7 (CVSS:3.1/AV:N/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 (tested at master commit d95483f), STM32 builds that seed from the hardware RNG through the Standard Peripheral Library branch of wc_GenerateSeed
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
On STM32 targets, wc_GenerateSeed() reads seed bytes from the chip's hardware random number generator. The function has several branches. The bare-metal branch (WOLFSSL_STM32_RNG_NOLIB) waits a bounded time for each byte, detects the generator's seed-error and clock-error conditions, recovers the peripheral, and returns an error after a limited number of retries.
The Standard Peripheral Library branch in the same conditional block does not. Its per-byte loop waits for the data-ready flag with no timeout. If the generator latches a seed or clock error partway through the fill, it stops asserting data-ready and the loop spins forever.
The result is a hang, not weak entropy. The function holds the crypto hardware mutex at that point, so RNG initialization or reseeding never completes. The trigger is a hardware condition. Default builds do not compile this branch.
Affected Products and Versions
- Component:
wolfcrypt/src/random.c,wc_GenerateSeed(), STM32 Standard Peripheral Library branch (wolfcrypt/src/random.c:8497-8534). - Required build: the STM32 hardware RNG family selected at
wolfcrypt/src/random.c:8240(WOLFSSL_STM32F427_RNGand related), in the non-CubeMX, non-bare-metal configuration. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default build does not include this code.
- Other releases were not checked.
Technical Details
The byte loop is at wolfcrypt/src/random.c:8523-8529:
for (i = 0; i < sz; i++) {
/* wait until RNG number is ready */
while (RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET) { }
/* get value */
output[i] = RNG_GetRandomNumber();
}
- The function takes the crypto hardware mutex, enables the RNG clock and resets and enables the peripheral.
- It checks the seed-error and clock-error flags once, before the loop (
wolfcrypt/src/random.c:8518-8521), and returnsRNG_FAILURE_Eif either is set. - For each output byte it polls
RNG_FLAG_DRDYuntil the flag is set. There is no timeout, no error-flag check inside the loop and no retry limit. - If an error latches after step 2, the peripheral stops asserting data-ready. The
whileloop does not exit, and the mutex is never released.
The bare-metal branch documents this failure in its own comment (wolfcrypt/src/random.c:8257-8264): the unbounded loop "spins forever on chips where the RNG kernel clock is unstable". That branch bounds each wait with STM32_BARE_RNG_BYTE_TIMEOUT (wolfcrypt/src/random.c:8417-8424), breaks on the error flags, and enforces a retry budget. The Standard Peripheral Library branch has none of this.
Reachability and Preconditions
- Build: an STM32 target that uses the Standard Peripheral Library RNG branch. Off by default.
- The RNG peripheral must latch a seed-error or clock-error condition during the fill, after the pre-loop check. This happens with a marginal or failing RNG kernel clock.
- The condition is in the hardware. A remote party cannot set it through protocol input.
- Any caller that seeds or reseeds the DRBG reaches the loop: RNG initialization and periodic reseeding.
Impact
wc_GenerateSeed() does not return. The crypto hardware mutex stays held, the DRBG is never seeded or reseeded, and every later consumer of the RNG, including the TLS stack, blocks. The effect is on availability only. No seed bytes are taken from a failed generator, so confidentiality and integrity are not affected.
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 give the Standard Peripheral Library branch the same handling as the bare-metal branch: a bounded per-byte wait, a check of the seed-error and clock-error flags inside the wait, the peripheral recovery sequence under a retry budget, and RNG_FAILURE_E when the budget is used up. A shared helper for both branches would keep them aligned. Where the platform allows it, the bare-metal RNG option (WOLFSSL_STM32_RNG_NOLIB) uses the bounded wait.
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.