← ALL ADVISORIES

HIGH BYTERAY-2026-0337Patched

wolfSSL — Heap Out-of-Bounds Write in TLS Record Decompression Copy-Back

With TLS compression enabled, wolfSSL 5.0.1 inflated an application data record into a stack buffer and then copied the expanded data back into the heap input buffer, which was sized for the compressed record. A peer could write up to about 17 KB of chosen data past the end of that buffer.

Advisory
BYTERAY-2026-0337
CWE
CWE-122
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-20
Disclosure
2026-12-03
Affected
wolfSSL 5.0.1 (tested), builds with zlib support (--with-libz) where the application enables compression, TLS 1.2 and earlier. The v5.9.2-stable tag carries the same copy-back.
Fixed in
wolfSSL 5.9.4 (commit d8998da0c97e1feb9a77658ce6040e1478c8d311, PR 11186, merged 2026-09-15).
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL can compress TLS records with zlib when it is built with --with-libz and the application calls wolfSSL_set_compression(). On receive, DoApplicationData() inflates the record body into a local buffer and then copies the result back over the record in the connection's input buffer.

The input buffer is grown to hold the record as it arrived, which is the compressed size. The copy-back uses the expanded size and does not check it against the space left in the buffer. A small record that inflates to many kilobytes therefore writes past the end of the heap allocation with bytes the peer chose.

The record is processed after the handshake has completed and after the record has passed its integrity check, so the attacker is the TLS peer. Default builds are not affected: zlib support is off by default, and compression must also be requested by the application.

Affected Products and Versions

  • Product: wolfSSL, TLS record layer, builds with HAVE_LIBZ (--with-libz).
  • Runtime condition: the application calls wolfSSL_set_compression() and the peer negotiates zlib compression. Compression is not available in TLS 1.3.
  • Tested: wolfSSL 5.0.1 (tag WCv5.2.4-KRNL-CHKIN-r12, commit 38cc7b133bb4964404a0ca08d2c2303bb139c852).
  • The v5.9.2-stable tag still contains the copy-back statement. ByteRay did not test that release.
  • The v5.9.4-stable tag does not. Since commit d8998da0c97e1feb9a77658ce6040e1478c8d311 (PR 11186, merged 2026-09-15), DoApplicationData() inflates into a separate buffer owned by the connection and no longer copies back.
  • A default ./configure build does not include this code.

Technical Details

DoApplicationData() declares a stack buffer for the inflated data (src/internal.c:16118). It holds MAX_RECORD_SIZE + MAX_COMP_EXTRA bytes, 16384 plus the compression allowance.

When compression is in use, the record body is inflated into that buffer and dataSz becomes the expanded length (src/internal.c:16196). myDeCompress() bounds the inflate by the size of the stack buffer, so this step is safe.

The function then copies the expanded data back to rawData, which points into the connection's input buffer (src/internal.c:16215). The source comment reads "decompress could be bigger, overwrite after verify". The length is dataSz, the expanded size. No check compares it with the room left in the input buffer.

GrowInputBuffer() allocates the input buffer from the size of the incoming record and the bytes already held (src/internal.c:9205). It adds no slack for expansion.

The data flow is:

  1. The peer sends a compressed application data record. The record on the wire is small.
  2. The input buffer is grown to the size of that record.
  3. The record is decrypted in place and verified.
  4. The body is inflated into the stack buffer. The result can be as large as the stack buffer.
  5. The expanded data is copied back into the input buffer at the position of the record body. Everything beyond the end of the allocation is written to adjacent heap memory.

Reachability and Preconditions

  • Build: --with-libz (HAVE_LIBZ). Off by default.
  • Runtime: the application calls wolfSSL_set_compression(), and the handshake negotiates zlib compression with the peer.
  • Protocol: TLS 1.2 or earlier.
  • Attacker position: the TLS peer, client or server, after the handshake has completed. The record must be a valid record for the session, so a third party on the network cannot trigger this.
  • Authentication: whatever the handshake required. A server that does not request client certificates is exposed to any client.

Impact

A peer can write past the end of the heap input buffer. The length of the overrun is the expanded size minus the room left in the buffer, up to about 17 KB, and the content is the peer's own inflated data. The write is deterministic.

The minimum result is a crash of the process. Depending on the allocator and on what follows the input buffer on the heap, corruption of adjacent objects may allow code execution.

Remediation and Mitigation

Update to wolfSSL 5.9.4 or later. That release inflates into a separate buffer owned by the connection and passes that buffer to the application, so the input buffer is never written with expanded data.

If an update is not possible:

  • Do not call wolfSSL_set_compression(). TLS-level compression is also exposed to compression side channels and is not recommended in general.
  • Build without --with-libz where zlib support is not required.

Timeline

  • 2026-08-17 — wolfSSL committed d8998da ("Fix heap overflow in TLS compression receive path") upstream.
  • 2026-09-15 — PR 11186 merged to master.
  • 2026-09-20 — Reported to wolfSSL against version 5.0.1.
  • 2026-09-25 — wolfSSL tagged v5.9.4-stable, which contains the fix.
  • 2026-12-03 — Public disclosure.

Credits

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

The upstream fix predates ByteRay's report. ByteRay found the issue independently in the 5.0.1 code.

References