← ALL ADVISORIES

LOW BYTERAY-2026-0493Disclosed

wolfSSL — Infinite Loop on Zero-Byte Read from /dev/hwrng in wc_hwrng_generate_block

In builds with WOLFSSL_KCAPI and CUSTOM_RAND_GENERATE_BLOCK, wc_hwrng_generate_block fills the request from /dev/hwrng in a loop that treats only a return of -1 from read() as an error. A read that returns zero bytes makes no progress, so the loop never ends and the calling thread spins.

Advisory
BYTERAY-2026-0493
CWE
CWE-252
CVSS
2.5 (CVSS:3.1/AV:L/AC:H/PR:L/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), builds that define both WOLFSSL_KCAPI and CUSTOM_RAND_GENERATE_BLOCK
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

With the kernel crypto API backend, wolfSSL can take its random blocks from /dev/hwrng. wc_hwrng_generate_block() opens the device and reads until the request is filled. The loop stops on a read() return of -1 and nowhere else. A return of zero, which is how a character device signals end of file, leaves the remaining length and the output pointer unchanged. The loop then repeats the same read indefinitely. The calling thread stays at full CPU and its request for random bytes never completes.

The output buffer is cleared before the call and is handed back only on success, so nothing uninitialized escapes. The impact is availability of the calling thread. The device state that causes a zero read is a local condition, and this build combination is not a default.

Affected Products and Versions

  • Component: wolfcrypt/src/random.c, wc_hwrng_generate_block().
  • Required build: WOLFSSL_KCAPI and CUSTOM_RAND_GENERATE_BLOCK both defined (wolfcrypt/src/random.c:9937). In that case the header redefines CUSTOM_RAND_GENERATE_BLOCK as wc_hwrng_generate_block (wolfssl/wolfcrypt/random.h:226-235). The --enable-kcapi options define WOLFSSL_KCAPI (configure.ac:5155); the second macro has to be supplied by the builder.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include this code, and no configuration in the tree ships this combination.
  • Other releases were not checked.

Technical Details

The function is at wolfcrypt/src/random.c:9939-9959. Its fill loop:

    while(sz)
    {
        int len = (int)read(fd, output, sz);
        if (len == -1)
        {
            ret = READ_RAN_E;
            break;
        }
        sz -= len;
        output += len;
    }

Data flow:

  1. wc_RNG_GenerateBlock() clears the output buffer and calls the block generator (wolfcrypt/src/random.c:5666-5667).
  2. wc_hwrng_generate_block() opens /dev/hwrng. An open failure returns OPEN_RAN_E (wolfcrypt/src/random.c:9943-9945).
  3. read() returns the number of bytes delivered (wolfcrypt/src/random.c:9948).
  4. With len == 0, sz -= len and output += len change nothing, and while(sz) is still true. The loop has no other exit.

The loop that reads the seed device in the same file handles this case. It breaks on len <= 0 under the comment "EOF never fills the request, don't retry forever" (wolfcrypt/src/random.c:9870-9876). Because CUSTOM_RAND_GENERATE_BLOCK is defined, the RNG auto-lock is not compiled in (wolfssl/wolfcrypt/random.h:42-53). The spin is therefore confined to the calling thread and does not hold a lock that other RNG users need.

Reachability and Preconditions

  • The library is built with both macros and the host has /dev/hwrng.
  • The device returns zero bytes during a request. This happens when the active hardware RNG has been unregistered or is in a fault state, which takes a local privileged action or a driver fault. There is no remote trigger, and a local actor able to force the device state already holds comparable privileges.
  • Any caller of wc_RNG_GenerateBlock(), wc_RNG_GenerateByte() or wolfSSL_RAND_bytes() then enters the loop, for example during a TLS handshake or key generation.

Impact

The calling thread hangs at full CPU and the operation that needed random bytes never finishes. Other threads continue. No data is disclosed or altered.

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 treat any non-positive return from read() as terminal: map a zero return to READ_RAN_E and leave the loop, as the seed-device loop already does. Positive short reads need no change, because the existing arithmetic advances the request. Builds that do not define CUSTOM_RAND_GENERATE_BLOCK together with WOLFSSL_KCAPI are not affected.

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.

References