← ALL ADVISORIES

MEDIUM BYTERAY-2026-0389Disclosed

wolfSSL — Predictable TCP Initial Sequence Numbers from Unseeded rand() in the RA6M3 FreeRTOS+TCP Port

The FreeRTOS+TCP glue shipped with the Renesas RA6M3 example projects returns libc rand() as the TCP initial sequence number and never calls srand(). Every device built from it produces the same sequence on every boot, which lets an off-path party predict sequence numbers and inject segments or resets.

Advisory
BYTERAY-2026-0389
CWE
CWE-337
CVSS
5.6 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), the Renesas RA6M3 e2studio example projects server-wolfssl and client-wolfssl, and products derived from them
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

FreeRTOS+TCP asks the application for the initial sequence number (ISN) of each TCP connection through a hook, ulApplicationGetNextSequenceNumber(). The ISN is sent in the clear in the SYN and is what stops an off-path party from forging segments for a connection.

The RA6M3 example port implements the hook by returning rand(). It ignores the connection's addresses and ports, and nothing in the RA6M3 tree calls srand(). An unseeded rand() behaves as if seeded with 1, so the ISN sequence is the same on every boot of every device built from this port.

The file is compiled into the server-wolfssl and client-wolfssl example projects. A comment in it says the implementations are not suitable for production, but nothing enforces that. The wolfSSL library itself and its ./configure build do not contain this code.

Affected Products and Versions

  • Component: IDE/Renesas/e2studio/RA6M3/common/src/freertos_tcp_port.c, ulApplicationGetNextSequenceNumber() and ulRand().
  • Required build: the RA6M3 server-wolfssl or client-wolfssl e2studio project, or a product that reuses this port file. The wolfCrypt benchmark project does not use it.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build of the library does not include this code.
  • Other releases were not checked.

Technical Details

The hook is at IDE/Renesas/e2studio/RA6M3/common/src/freertos_tcp_port.c:54-65. It casts its four parameters to void and returns ulRand(), defined at IDE/Renesas/e2studio/RA6M3/common/src/freertos_tcp_port.c:45-47:

uint32_t ulRand(void) {
    return (uint32_t) rand();
}

Data flow:

  1. The TCP stack calls the hook to obtain the ISN of each TCP connection.
  2. The hook discards the four connection parameters and returns ulRand().
  3. ulRand() returns the next value of libc rand(). No srand() call exists under IDE/Renesas, so the generator starts from the C default seed of 1.
  4. The stack places the value in the sequence field of the SYN and sends it to the peer.

rand() also returns at most RAND_MAX, which on many C libraries is 15 or 31 bits wide. The top bits of the 32-bit ISN then never change.

The comment at IDE/Renesas/e2studio/RA6M3/common/src/freertos_tcp_port.c:30-34 states that the callbacks in the file are not suitable for production and are not secure. It is the only ISN hook shipped in the tree, and both TLS example projects link it.

Reachability and Preconditions

  • The device runs one of the two example projects, or firmware that kept this port file, on RA6M3 hardware.
  • The attacker can reach the device's network. Observing one connection, or knowing the fixed rand() sequence of the C library in use, is enough to predict later ISNs.
  • No authentication or privilege is needed. The ISN is exposed before any TLS exchange.
  • An injected segment must also match the connection's addresses and ports and fall inside the receive window.

Impact

Predictable ISNs allow off-path TCP injection. A forged RST with a predicted sequence number tears down a connection the device opened, including the TCP connection under a wolfSSL TLS session. On flows without TLS, forged data can be inserted into the byte stream. TLS record protection still rejects forged application data, so for TLS sessions the effect is loss of the connection.

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 build ulRand() on the RA6M3 hardware random number generator or on wolfSSL's WC_RNG, both of which these projects already have. Better still, derive the ISN as RFC 6528 describes: a keyed hash over the connection's addresses and ports with a per-boot secret, plus a monotonic offset. Adding a time-based srand() call is not sufficient, because rand() remains predictable and narrow.

Products derived from these examples should replace the hook before deployment.

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