← ALL ADVISORIES

HIGH BYTERAY-2026-0314Disclosed

wolfSSL — Heap Out-of-Bounds Read in Sniffer from Unvalidated TLS 1.3 Record Padding Size

For TLS 1.3 records the wolfSSL sniffer derives the padding size from the decrypted plaintext and does not bound it. The handshake record loop advances by that size without adjusting its remaining-bytes count, so a following handshake message can make the sniffer read up to about a full record length past the heap buffer that holds the decrypted record.

Advisory
BYTERAY-2026-0314
CWE
CWE-125
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 and WOLFSSL_TLS13 where the sniffer holds keys for the inspected TLS 1.3 session
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

A TLS 1.3 record carries its real content type and optional zero padding inside the encrypted payload. The wolfSSL sniffer finds them after decryption by scanning the plaintext backwards for the first non-zero byte. Everything from that byte to the end of the record, including the authentication tag, is counted as ssl->keys.padSz.

The scan has no effective lower bound. The one guard before it cannot be true on this path, and nothing checks that content remains once the padding is removed or that the recovered content type is valid. The sender of the record decides how much of it is padding, so padSz can approach the size of the whole record.

The handshake case of the sniffer's record loop then advances its cursor by padSz without reducing its remaining-bytes count. A following handshake message is checked against the stale count, and the parsers and the transcript hash read past the end of the heap buffer by up to padSz bytes. An endpoint of a sniffed TLS 1.3 session can crash the monitoring process this way. The sniffer is not part of a default build.

Affected Products and Versions

  • Component: src/sniffer.c, the TLS 1.3 padding derivation in DecryptMessage(), with the out-of-bounds read in the handshake case of ProcessMessage().
  • Required build: WOLFSSL_SNIFFER (--enable-sniffer) with TLS 1.3 (WOLFSSL_TLS13), in a deployment where the sniffer can decrypt the TLS 1.3 session through a key log, ticket keys or a key callback.
  • Every TLS 1.3 encrypted handshake record that the sniffer decrypts goes through this code.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include the sniffer.
  • Other releases were not checked.

The missing count adjustment in the record loop is described in BYTERAY-2026-0312, which covers the TLS 1.2 case. This advisory covers the TLS 1.3 source of the padding size.

Technical Details

DecryptMessage() rejects a TLS 1.3 record that is not longer than the AEAD tag (src/sniffer.c:5439) and decrypts it with DecryptTls13() (src/sniffer.c:5443). It then derives the padding (src/sniffer.c:5504-5518):

        word16 i = (word16)(sz - ssl->keys.padSz);
        if (i == 0) {
            *error = BUFFER_ERROR;
            return NULL;
        }
        /* Remove padding from end of plain text. */
        for (--i; i > 0; i--) {
            if (output[i] != 0)
                break;
        }
        /* Get the real content type from the end of the data. */
        rh->type = output[i];
        ssl->keys.padSz = sz - i;

The i == 0 check (src/sniffer.c:5507) cannot be true here, because the earlier length check already requires the record to be longer than the tag. It tests that the record has plaintext. It does not test that content is left after the padding is stripped. The loop stops at the highest non-zero plaintext byte, takes it as the content type, and sets padSz = sz - i (src/sniffer.c:5518). The lower that byte sits in the plaintext, the larger padSz becomes.

DecryptTls13() verifies the tag. That does not constrain an endpoint of the session, which holds the traffic keys and produces valid records.

From there the flow is the one in BYTERAY-2026-0312:

  1. ssl_DecodePacket() (src/sniffer.c:7326) hands the captured record to ProcessMessage() (src/sniffer.c:7271).
  2. ProcessMessage() sizes the output buffer for the record (src/sniffer.c:6776) and sets recordEnd to the end of that buffer (src/sniffer.c:6786).
  3. DecryptMessage() takes the TLS 1.3 branch and sets ssl->keys.padSz from the backward scan.
  4. The handshake case processes one message and advances sslFrame by the message and by padSz. It does not reduce sslBytes by padSz (src/sniffer.c:6834-6836).
  5. The loop continues while sslFrame < recordEnd (src/sniffer.c:6999) and enters the handshake case again with the stale count.
  6. DoHandShake() accepts a declared body length up to that count (src/sniffer.c:4960, src/sniffer.c:5151). The message handlers and the HashRaw() calls (src/sniffer.c:5012-5013) read that many bytes, past recordEnd.

Reachability and Preconditions

  • The library is built with WOLFSSL_SNIFFER and WOLFSSL_TLS13, and the application feeds captured packets to ssl_DecodePacket().
  • The sniffer can decrypt the TLS 1.3 session. Decryption is active for every encrypted handshake record of such a session.
  • The record is large enough that the output buffer is a dynamic allocation of the record size.
  • Attacker position: a remote endpoint of a TLS 1.3 session that crosses the monitored link. As an endpoint it holds the traffic keys, so it produces records with valid tags and chooses the plaintext, the declared lengths and the amount of 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. The read extends up to padSz bytes past the decrypted record, and padSz can be close to the record size, about 1 KB in the case ByteRay examined. The TLS 1.2 AEAD case of the same loop is limited to a fixed 16 bytes.

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 handshake parsers and the transcript hashes. 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 has two parts. The TLS 1.3 padding scan in DecryptMessage() should replace the ineffective i == 0 check with real validation: the recovered inner content type must be a legal record type, and content must remain after the padding is removed. A cap on ssl->keys.padSz against the decrypted size is a reasonable additional guard. Separately, the handshake case of ProcessMessage() should reduce the remaining count by ssl->keys.padSz when it advances the cursor, stop processing the record if the result is not positive, and check the cursor and count against recordEnd before the loop is entered again.

ByteRay has identified no configuration workaround for a sniffer deployment that decrypts TLS 1.3 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