← ALL ADVISORIES

LOW BYTERAY-2026-0495Disclosed

wolfSSL — Infinite Loop in wolfSSL_RAND_egd from Stale errno Retry Check

The entropy collection loop in wolfSSL_RAND_egd tests errno for EAGAIN or EINTR before it tests for a zero-entropy reply, without checking that the preceding call failed. With a stale errno value, every zero-entropy reply from the EGD daemon is retried and the loop never exits.

Advisory
BYTERAY-2026-0495
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), POSIX builds that provide wolfSSL_RAND_egd, when the application seeds from an EGD socket
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL_RAND_egd() is an OpenSSL-compatible API that seeds the random number generator from an EGD-style entropy daemon over a local UNIX-domain socket. Each reply from the daemon starts with a length byte. The loop is designed to stop when that byte is zero, which means the daemon has no more entropy.

The branch that decides whether to retry is evaluated before the zero-entropy stop, and it tests errno alone. POSIX does not reset errno when a call succeeds. A value of EINTR left behind by any earlier interrupted call is still there. Once it is, every zero-entropy reply is treated as a transient condition and retried. The byte counter does not advance and the loop condition stays true.

The seeding thread spins at full CPU and the call does not return. The consequence is local availability only. It requires an application that calls this API, a daemon behind the configured socket that answers with zero-length replies, and one earlier interrupted system call.

Affected Products and Versions

  • Component: src/ssl_crypto.c, wolfSSL_RAND_egd(), declared in wolfssl/ssl.h:2311.
  • Required build: a POSIX build that provides this API with the EGD protocol block compiled (src/ssl_crypto.c:3842-3845). The block is selected by platform conditions in the source, not by a dedicated configure option.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The function has no callers inside the library. A build is exposed only when the application calls it. Other releases were not checked.

Technical Details

The fill loop at src/ssl_crypto.c:3901 runs while bytes < 255 && idx + 2 < 256. Each pass writes a two-byte request (src/ssl_crypto.c:3902-3904) and reads the reply (src/ssl_crypto.c:3917). The only place that advances bytes and idx is the progress branch at src/ssl_crypto.c:3923-3931, which requires a positive length byte. When that branch is not taken, the code at src/ssl_crypto.c:3938-3947 runs:

            if (errno == EAGAIN || errno == EINTR) {
                WOLFSSL_MSG("EGD would read");
                ret = WOLFSSL_SUCCESS; /* try again */
            }
            else if (buf[idx] == 0) {
                /* if egd returned 0 then there is no more entropy to be had.
                   Do not try more reads. */
                ret = WOLFSSL_SUCCESS;
                break;
            }

The errno test comes first and does not check that the read() failed. Nothing resets errno around the write() and the read(). Two adjacent checks work as intended and do not cover this case: end of file (read() returning 0, src/ssl_crypto.c:3918-3921) and a malformed length byte (src/ssl_crypto.c:3925-3929).

How the loop stops making progress:

  1. The application calls wolfSSL_RAND_egd() with the socket path, and the function connects (src/ssl_crypto.c:3891). An earlier system call in the thread was interrupted and left errno == EINTR.
  2. The daemon answers a request with a reply whose length byte is zero. read() returns a positive count and buf[idx] == 0.
  3. The progress test at src/ssl_crypto.c:3923 fails. The retry branch at src/ssl_crypto.c:3938-3941 is taken and sets ret back to WOLFSSL_SUCCESS.
  4. The stop at src/ssl_crypto.c:3942-3947 is not reached. bytes and idx are unchanged, so the loop condition still holds and the next pass repeats the same steps.

Reachability and Preconditions

  • The application calls wolfSSL_RAND_egd(path) against a local EGD-style UNIX socket. This is a deliberate, legacy configuration. It is not reachable from remote input, and no authentication is involved.
  • The daemon replies with zero-entropy records. That happens when its entropy is exhausted, or when a local actor controls or replaces the service behind the configured path.
  • At least one earlier system call in the thread was interrupted, for example by a caught signal, and errno still holds EINTR.

Impact

The RNG-seeding thread hangs permanently, and with it the application start-up that waits for it. The effect is on availability only. No entropy is accepted or corrupted, since a zero-entropy reply carries no data beyond the length byte. An actor who controls the entropy service gains nothing beyond hanging the seeding of the process that trusted it.

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 consult errno only when the call failed: test ret == -1 together with EAGAIN or EINTR, so that a successful read with a zero length byte falls through to the zero-entropy stop. Evaluating the buf[idx] == 0 stop before any retry logic has the same effect. A bound on consecutive replies that make no progress would remove the hang under any combination of daemon behaviour and errno state. Applications that do not seed from an EGD daemon are not affected. Those that do can clear errno immediately before calling wolfSSL_RAND_egd(). That removes a value left by an earlier call. It does not cover a call interrupted inside the function.

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