← ALL ADVISORIES

LOW BYTERAY-2026-0512Disclosed

wolfSSL — Missing Zeroization of Handshake and Record Buffers on Connection Teardown

When a connection is freed, wolfSSL clears keys and secrets but releases the handshake reassembly buffer, the threaded-crypt staging buffers and the WOLFSSL object's inline record buffers without clearing them. Decrypted handshake data, and in some builds application plaintext, remains in freed heap memory.

Advisory
BYTERAY-2026-0512
CWE
CWE-226
CVSS
3.7 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/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), default builds for the handshake reassembly buffer; WOLFSSL_THREADED_CRYPT and LARGE_STATIC_BUFFERS builds leave additional data
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL_free() tears a connection down through FreeSSL() and wolfSSL_ResourceFree(). That code clears most secret material with ForceZero() before it frees it: the key block, the TLS 1.3 traffic secrets, the Finished data, the DH private value, the cookie secrets and the decompression buffer.

Three resources that hold plaintext are not cleared. The handshake reassembly buffer ssl->pendingMsg is freed as it is. With WOLFSSL_THREADED_CRYPT, the per-slot staging buffers are freed as they are. The WOLFSSL object itself is freed with its inline static input and output buffers still holding record data.

The first case is in default builds and leaves decrypted handshake messages in freed memory. The other two need non-default options. Reading any of it requires a separate way to read reused heap memory in the same process.

Affected Products and Versions

  • Component: src/internal.c, wolfSSL_ResourceFree() and FreeSSL().
  • Default builds: the ssl->pendingMsg release, and the release of the WOLFSSL object with a 5-byte record header left in each static buffer.
  • WOLFSSL_THREADED_CRYPT builds (off by default): the threaded-crypt slot buffers.
  • LARGE_STATIC_BUFFERS builds, or builds that set STATIC_BUFFER_LEN: full records in the inline static buffers.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • Other releases were not checked.

Technical Details

The teardown chain is wolfSSL_free() (src/ssl.c:797-804), FreeSSL() (src/internal.c:10490), wolfSSL_ResourceFree() (src/internal.c:9884). The three releases:

  1. ssl->pendingMsg is the buffer in which fragmented handshake messages are reassembled. It is freed at src/internal.c:9908 with no overwrite. In TLS 1.3 it can hold decrypted EncryptedExtensions, Certificate and Finished messages. The same bare free is used when reassembly completes (src/internal.c:21120, src/tls13.c:16396) and when the object is reused (src/ssl.c:6060).
  2. Under WOLFSSL_THREADED_CRYPT, application data is staged in a slot buffer (src/internal.c:29738-29744) and the worker encrypts it in place (src/ssl.c:10455-10477). Until the worker has run, the buffer holds plaintext. Teardown sets the slot's stop flag (src/internal.c:9999) and frees the buffer (src/internal.c:10002-10003). It does not clear the buffer and does not wait for in-flight work.
  3. FreeSSL() frees the WOLFSSL object at src/internal.c:10497. The object contains inputBuffer.staticBuffer and outputBuffer.staticBuffer, sized by STATIC_BUFFER_LEN in wolfssl/internal.h. By default that is one record header. With LARGE_STATIC_BUFFERS it is a full record, which can be decrypted application data.

The surrounding code shows the pattern that is missing. wolfSSL_ResourceFree() clears the key block (src/internal.c:9940), the TLS 1.3 secrets (src/internal.c:9943-9944), the Finished data (src/internal.c:9958-9959) and the decompression buffer (src/internal.c:10070). ShrinkInputBuffer() and ShrinkOutputBuffer() clear the dynamic record buffers before freeing them (src/internal.c:12526-12527, src/internal.c:12451-12453).

FreeSSL() also contains a check that the object is zero before it is freed, wc_MemZero_Check() at src/internal.c:10494-10496. It is compiled only with WOLFSSL_CHECK_MEM_ZERO, a debug option, so release builds do not enforce it.

Reachability and Preconditions

  • Any application that frees a WOLFSSL object reaches the pendingMsg and object releases. No special runtime configuration is needed.
  • pendingMsg holds data only if the connection received a fragmented handshake message. A TLS peer controls that.
  • The threaded-crypt case needs WOLFSSL_THREADED_CRYPT. The full-record case needs LARGE_STATIC_BUFFERS or a larger STATIC_BUFFER_LEN.
  • Disclosure needs a second condition outside this issue: the freed block is reused in the same process and something exposes the reused memory.

Impact

Decrypted handshake plaintext, and in the non-default configurations application plaintext, persists in freed heap memory after the connection is gone. A later allocation in the same process can receive that memory. The exposure is limited to confidentiality and depends on a separate memory-disclosure primitive.

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 apply ForceZero() at the three release sites: to ssl->pendingMsg over its recorded size before each free, to every threaded-crypt slot buffer before its free, and to the inline static buffers or the whole WOLFSSL object before the final free. Teardown should also wait for, or cancel, in-flight threaded work instead of relying on the stop flag. Clearing the whole object unconditionally before the last free would make the debug-only invariant hold in release builds.

Leaving WOLFSSL_THREADED_CRYPT and LARGE_STATIC_BUFFERS off avoids the two application-data cases. There is no configuration workaround for the pendingMsg case.

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