wolfSSL — Out-of-Bounds Read in Sniffer Static-RSA ClientKeyExchange Handling
In the sniffer's static-RSA key setup, SetupKeys skips the two-byte length prefix of the ClientKeyExchange body and then checks the RSA ciphertext length against the byte count from before the skip. A body exactly as long as the ciphertext, or one byte longer, makes the RSA decryption read up to two bytes past the heap buffer that holds the message.
- Advisory
- BYTERAY-2026-0440
- CWE
- CWE-125
- 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), sniffer builds (WOLFSSL_SNIFFER) with a server RSA key loaded and a static-RSA cipher suite negotiated
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
When the wolfSSL sniffer holds the server's RSA private key, it decrypts the premaster secret of a static-RSA handshake in SetupKeys(). For TLS the ClientKeyExchange body starts with a two-byte length, which the code skips before it passes the ciphertext to the RSA decryption.
The length check that follows does not account for the skip. It compares the expected ciphertext size with the number of bytes that were available before the pointer moved. A ClientKeyExchange body that is exactly the ciphertext size, or one byte more, passes the check. The decryption then reads the full ciphertext size from the advanced pointer, which is one or two bytes past the end of the message. The extra bytes only feed the RSA decryption, and its output is discarded on this input. Nothing is disclosed or written. The consequence is limited to a crash of the sniffer process when the heap buffer ends at an unmapped page. The sniffer is not part of a default build.
Affected Products and Versions
- Component:
src/sniffer.c,SetupKeys(), the static-RSA branch. - Required build:
WOLFSSL_SNIFFER(--enable-sniffer) with RSA and static-RSA cipher suites available. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include the sniffer. - Other releases were not checked.
Technical Details
The static-RSA branch sets the expected length, skips the prefix and then validates (src/sniffer.c:2786-2797):
args->length = wc_RsaEncryptSize(&args->key->priv.rsa);
if (IsTLS(session->sslServer)) {
input += 2; /* tls pre length */
}
if (args->length > *sslBytes) {
*sslBytes is not reduced when input advances. After the skip only *sslBytes - 2 bytes are valid at input. The consumer is wc_RsaPrivateDecrypt(input, args->length, ...) at src/sniffer.c:3256. The validated quantity and the consumed quantity differ by two.
- The client's ClientKeyExchange reaches
ProcessClientKeyExchange(), which callsSetupKeys()on the static-key path (src/sniffer.c:3508-3526). It adds no length check of its own. args->lengthis the RSA modulus size, 256 for a 2048-bit key.inputadvances by two (src/sniffer.c:2789).- The check at
src/sniffer.c:2792passes when*sslBytesis 256 or 257. - The decryption reads 256 bytes from the advanced pointer. Two bytes, or one, are past the end of the message.
The sniffer's input buffer is allocated to the exact size of the data it holds, with no padding for TCP (src/internal.c:12800). When the ClientKeyExchange is the last message in that buffer, the read leaves the heap block.
Reachability and Preconditions
- Sniffer build, with the monitored server's RSA private key loaded. This is the standard keyfile deployment.
- The monitored session negotiates a static-RSA cipher suite.
- The attacker is the TLS client of the monitored session, or controls that client's traffic. The sniffer applies no authentication to captured handshake bytes.
- The crafted ClientKeyExchange must end an exactly sized input buffer. The client can arrange this by splitting the message across records or TCP segments.
Impact
A remote, unauthenticated heap over-read of one or two bytes in the sniffer process. The bytes are consumed by the RSA decryption and do not reach any output. The process can crash if the allocation ends at an unmapped page boundary, which stops monitoring. The outcome depends on heap layout.
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 keep the byte count in step with the pointer: reject a body shorter than two bytes, reduce the remaining count when the prefix is skipped, and compare the ciphertext length with that reduced count. The same accounting applies to every place in this function that advances input without adjusting the validated length. BYTERAY-2026-0441 describes the same pattern in the static-ECC branch. A sniffer that does not load an RSA private key does not take this branch.
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
- Static-RSA branch of
SetupKeysat the tested commit - RSA decryption call at the tested commit
- BYTERAY-2026-0438, heap out-of-bounds read in the sniffer reassembly record scanner
- BYTERAY-2026-0439, out-of-bounds read in the sniffer pre-shared-key extension parser
- BYTERAY-2026-0441, one-byte over-read in the sniffer static-ECC key exchange