← ALL ADVISORIES

HIGH BYTERAY-2026-0312Disclosed

wolfSSL — Heap Out-of-Bounds Read in Sniffer Handshake Record Loop from Unaccounted Padding Size

In the wolfSSL sniffer, the handshake case of the record loop advances its cursor past the decryption trailer but does not reduce the remaining-bytes count by the same amount. A following handshake message in the same record is then length-checked against a stale count, and the sniffer reads past the end of the heap buffer that holds the decrypted record.

Advisory
BYTERAY-2026-0312
CWE
CWE-129
CVSS
8.2 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:H)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-27
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with WOLFSSL_SNIFFER (--enable-sniffer) where the sniffer holds keys for the inspected session
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The wolfSSL sniffer decodes TLS traffic captured from a network link. When it holds keys for a session it decrypts each record into a buffer sized for that record and then walks the messages inside it. Two variables track the walk: a cursor, sslFrame, and a count of the bytes that remain, sslBytes.

In the handshake case of ProcessMessage(), the cursor is advanced past the handshake message and then past the decryption trailer, ssl->keys.padSz. The remaining-bytes count is not reduced by the trailer. When the record holds a further message, the next pass checks that message's declared length against a count that is too large by padSz. The handshake parsers and the transcript hash then read up to padSz bytes past the end of the heap buffer.

The party who can cause this is an endpoint of a session that the sniffer decrypts. The result is a crash of the monitoring process. The bytes read are not returned to the attacker. The sniffer is not part of a default build.

Affected Products and Versions

  • Component: src/sniffer.c, the handshake case of the record loop in ProcessMessage(), with the trailer length set in DecryptMessage().
  • Required build: WOLFSSL_SNIFFER (--enable-sniffer), in a deployment where the sniffer can decrypt the session: a configured RSA key file, a keyserver that returns the pre-master secret, or secrets supplied out of band.
  • The largest over-read is with TLS 1.2 CBC cipher suites, where the trailer includes the CBC padding. With AEAD suites the same accounting gap applies to a fixed 16-byte trailer per message.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include the sniffer.
  • Other releases were not checked.
  • The TLS 1.3 padding derivation that reaches the same loop is covered in BYTERAY-2026-0314.

Technical Details

ProcessMessage() reads the record header and sets recordEnd to the end of the record (src/sniffer.c:6743). For an encrypted record it sizes the output buffer for the record with CheckAvailableSize() (src/sniffer.c:6776), decrypts into that buffer, and recomputes recordEnd against it (src/sniffer.c:6786). The buffer is allocated at the record size, so recordEnd is the end of the heap block.

DecryptMessage() records the length of the trailer that follows the plaintext in ssl->keys.padSz. For block ciphers it adds the CBC padding length, taken from the last plaintext byte (src/sniffer.c:5493-5500):

        if (sz > (word32)ivExtra + macExtra) {
            /* get value of last pad byte */
            pad = *(output + sz - (word32)ivExtra - macExtra - 1) + 1;
        }
        ssl->keys.padSz += pad;

The value is not compared with the size of the decrypted data, and the sniffer does not verify the padding or the MAC.

After DoHandShake() returns, the handshake case moves the cursor (src/sniffer.c:6834-6836):

                used = startIdx - sslBytes;
                sslFrame += used;
                if (decrypted)
                    sslFrame += ssl->keys.padSz;

DoHandShake() has already reduced sslBytes by the message it consumed (src/sniffer.c:5151). Nothing reduces it by padSz. After this step sslFrame + sslBytes is padSz bytes beyond recordEnd. The application-data case of the same loop does make the adjustment (src/sniffer.c:6897).

The sequence:

  1. ssl_DecodePacket() (src/sniffer.c:7326) hands the captured record to ProcessMessage() (src/sniffer.c:7271).
  2. The record is decrypted into the record-sized output buffer and recordEnd marks its end.
  3. DecryptMessage() sets ssl->keys.padSz from the cipher suite and, for CBC, from the last plaintext byte.
  4. The handshake case processes one message and advances sslFrame by the message and by padSz, leaving sslBytes unchanged for the trailer.
  5. The loop continues while sslFrame < recordEnd (src/sniffer.c:6999) and enters the handshake case again.
  6. DoHandShake() accepts a declared body length up to the stale sslBytes (src/sniffer.c:4960). The message handlers and the HashRaw() calls (src/sniffer.c:5012-5013) read that many bytes, which runs past recordEnd.

Reachability and Preconditions

  • The library is built with WOLFSSL_SNIFFER, and the application feeds captured packets to ssl_DecodePacket().
  • The sniffer can decrypt the session, and decryption is active for the record. In TLS 1.2 that is any record after ChangeCipherSpec.
  • The record carries more than one handshake message and is large enough that the output buffer is a dynamic allocation of the record size.
  • Attacker position: a remote endpoint of a TLS session that crosses the monitored link, typically any client that can connect to a monitored server. As an endpoint it holds the session keys, so it chooses the decrypted handshake bytes, the declared lengths and the padding.
  • The other TLS endpoint does not need to accept the record. The sniffer parses what is on the wire.
  • No authentication to the sniffer and no user interaction.

Impact

A heap out-of-bounds read in the process that runs the sniffer. Each affected message reads up to padSz bytes past the decrypted record: the MAC length plus the CBC padding for block ciphers, which is roughly 288 bytes with SHA-256 and more with larger hashes, or 16 bytes for AEAD suites. The over-read can repeat for each further message in the record. The practical result is a crash of the monitoring process. Traffic is not inspected while it is down. The bytes read out of bounds go into the transcript hashes and the handshake parsers. The sniffer does not send them back to the attacker, so direct disclosure of memory contents is limited.

ByteRay reproduced this issue in an instrumented test build.

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 cursor and the count consistent in the handshake case of ProcessMessage(). After the cursor is advanced by ssl->keys.padSz, the remaining count should be reduced by the same amount, and the record abandoned if the result is not positive, as the application-data case already does. In addition, the CBC branch of DecryptMessage() should reject a padding length larger than the remaining plaintext, and DoHandShake() and the message handlers should be bounded by recordEnd as well as by the remaining count.

ByteRay has identified no configuration workaround for a sniffer deployment that decrypts sessions. Builds without WOLFSSL_SNIFFER do not contain this code.

Timeline

  • 2026-09-27 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References