← ALL ADVISORIES

MEDIUM BYTERAY-2026-0393Disclosed

wolfSSL — Decrypted Application Data Left in Freed Heap Memory on Sniffer Buffer Growth

The wolfSSL sniffer grows its decrypted-data buffer with a realloc for each application-data record. When the allocator moves the block, the old block is released with the plaintext decoded so far still in it. The failure path of the same call clears the buffer; the success path does not.

Advisory
BYTERAY-2026-0393
CWE
CWE-226
CVSS
5.9 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with WOLFSSL_SNIFFER (--enable-sniffer)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The wolfSSL sniffer decrypts TLS records of monitored connections and returns the application plaintext to the caller in a heap buffer. ProcessMessage() appends each decrypted application-data record to that buffer and grows it with XREALLOC().

A realloc that moves the buffer returns the old block to the allocator. That block still holds the plaintext accumulated so far, and nothing clears it. The error branch directly below the call does clear the buffer with ForceZero() before freeing it. The normal path is the one that leaves plaintext behind.

In an inspection deployment the plaintext belongs to the users whose traffic is monitored. Any later allocation in the same process can land on a stale block. Turning that into disclosure needs something that exposes the reused memory. The sniffer is not part of a default build.

Affected Products and Versions

  • Component: src/sniffer.c, ProcessMessage(), application-data branch.
  • Required build: WOLFSSL_SNIFFER (--enable-sniffer). The file is compiled only under that macro (src/sniffer.c:78), and the option is off by default (configure.ac:3162-3164).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include this code. Other releases were not checked.

Technical Details

ProcessMessage() (src/sniffer.c:6686) handles one TLS record at a time and tracks the bytes stored for the caller in decoded. For application data it grows the caller's buffer and appends (src/sniffer.c:6905-6917, error handling abridged):

                            tmpData = (byte*)XREALLOC(*data, decoded + ret + 1,
                                    NULL, DYNAMIC_TYPE_TMP_BUFFER);
                            if (tmpData == NULL) {
                                ForceZero(*data, decoded);
                                XFREE(*data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
                                /* ... set error and return ... */
                            }
                            *data = tmpData;
                            XMEMCPY(*data + decoded,
                                    ssl->buffers.clearOutputBuffer.buffer, ret);

The flow:

  1. A record is decrypted. ssl->buffers.clearOutputBuffer points at its plaintext.
  2. XREALLOC() resizes *data to hold the bytes already decoded plus the new record. With C realloc semantics, a moved block is freed by the allocator with its contents in place. On success the new pointer is stored and the new plaintext is appended. The old block is not touched again.
  3. decoded is advanced (src/sniffer.c:6953). Further records in the same input repeat the cycle (src/sniffer.c:6998-7001), so each growth can leave another stale copy.

The failure branch clears decoded bytes and then frees. The public helper ssl_FreeZeroDecodeBuffer() also clears this buffer before freeing it (src/sniffer.c:7388-7399). Both show that the contents are treated as sensitive on release. The success path of the realloc is the gap.

Reachability and Preconditions

  • The library is built with WOLFSSL_SNIFFER, and an application uses the sniffer API with a data pointer to receive decrypted plaintext. The sniffer holds the keys needed to decrypt the monitored flow, which is its normal configuration.
  • ProcessMessage() is on the main decode path. ssl_DecodePacketInternal() calls it (src/sniffer.c:7271), and the public entry points ssl_DecodePacket(), ssl_DecodePacketWithSessionInfo(), ssl_DecodePacketWithChain() and ssl_DecodePacketAsync() route through that function.
  • A monitored flow carries more than one application-data record in the data handed to one decode call. Ordinary traffic does this. The endpoints of the flow need no authentication to the sniffer.
  • Disclosure needs a second condition outside this issue: a later allocation in the same process receives a stale block and its contents are exposed, for example returned to another consumer, logged, or read through a separate memory-disclosure bug.

Impact

Decrypted application data of monitored third parties persists in freed heap memory during normal operation of the sniffer. Because the buffer grows per record, a busy sniffer produces many stale copies. With a way to read reused heap memory in the process, an attacker can recover plaintext from monitored sessions. Integrity and availability are not affected.

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 stop relying on the allocator to dispose of the old block. Replace the in-place growth with an explicit sequence: allocate the new block, copy the decoded bytes, clear the old block with ForceZero(), then free it. A zeroizing realloc helper used for every sniffer buffer that carries plaintext would apply the same rule everywhere. The added cost is linear in the bytes already decoded and small next to record decryption. There is no configuration workaround short of not building the sniffer. Builds without --enable-sniffer are not affected.

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