← ALL ADVISORIES

LOW BYTERAY-2026-0438Patched

wolfSSL — Heap Out-of-Bounds Read in the Sniffer Reassembly Record Scanner

When the wolfSSL sniffer recovers from missed data it scans buffered TCP segments for the start of a TLS record and reads three bytes from each buffer without checking its length. A buffered segment of one or two bytes is read past the end of its heap allocation, by one byte and at most two.

Advisory
BYTERAY-2026-0438
CWE
CWE-125
CVSS
3.7 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with --enable-sniffer, when recovery is enabled with ssl_EnableRecovery
Fixed in
Master commit 59179e8239cec5b4f7c5553b1149f765bcd173be (PR 12195, merged 2026-11-20). Not in a wolfSSL stable release as of 2026-12-03.
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The wolfSSL sniffer keeps out-of-order TCP payload in a per-direction reassembly list. Each entry is a heap buffer of exactly the payload length. A one-byte TCP segment produces a one-byte buffer.

When the sniffer sees an acknowledgement for data it never captured, and recovery has been enabled through ssl_EnableRecovery(), it stops waiting for the gap and looks for the next TLS record among the buffered segments. FindNextRecordInAssembly() tests the first three bytes of each buffer against the application-data record type and the session's protocol version. It does not look at the buffer's length first.

For a one-byte buffer whose byte is 0x17, the second comparison reads one byte past the allocation. For a two-byte buffer that starts 0x17 and the version major byte, the third comparison does. The byte is compared and thrown away. The effect is a heap over-read of one byte, or two when a one-byte buffer is followed by a byte equal to the version major, in the monitoring process. Recovery is off by default, and the sniffer is not part of a default build.

Affected Products and Versions

  • Component: wolfSSL sniffer, src/sniffer.c, FindNextRecordInAssembly().
  • Required build: --enable-sniffer (WOLFSSL_SNIFFER). Required run-time setting: recovery enabled with ssl_EnableRecovery() (src/sniffer.c:7436-7445). The switch defaults to off (src/sniffer.c:672).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same unchecked reads. Fixed on master by commit 59179e8239cec5b4f7c5553b1149f765bcd173be (PR 12195); no release contains the fix.
  • A default ./configure build does not include the sniffer. Earlier releases were not checked.

Technical Details

The scan loop, src/sniffer.c:6314-6319:

    while (curr != NULL) {
        *expected = curr->end + 1;

        if (curr->data[0] == application_data &&
            curr->data[1] == pv.major &&
            curr->data[2] == pv.minor) {

curr->data was allocated by CreateBuffer(), which computes added = end - *begin + 1, rejects only added <= 0 (src/sniffer.c:5965-5969) and allocates exactly added bytes (src/sniffer.c:5978). The only lower bound is one byte.

How a short buffer gets on the list and is scanned:

  1. AdjustSequence() passes out-of-order payload of any positive length to AddToReassembly() (src/sniffer.c:6248-6253). While a direction is in skip mode, in-order payload is buffered the same way (src/sniffer.c:6260-6263).
  2. AddToReassembly() stores the payload through CreateBuffer() with no minimum size (src/sniffer.c:6016, src/sniffer.c:6038, src/sniffer.c:6080).
  3. CheckSequence() calls CheckAck(). If a packet acknowledges data the sniffer has not seen and recovery is enabled, it calls FixSequence() (src/sniffer.c:6477-6493), which sets the skip flag for the direction whose data was missed (src/sniffer.c:6389-6393).
  4. On the next packet in that direction, CheckPreRecord() sees the flag and calls FindNextRecordInAssembly() (src/sniffer.c:6556-6560).
  5. The scan reads data[0], and if it is application_data (0x17), data[1], and if that equals the version major byte, data[2].

A buffer that fails the comparison is freed and the scan moves on (src/sniffer.c:6364-6371). The initialisation-vector read for block ciphers in the same loop is guarded by ivPos >= 0 and stays in bounds (src/sniffer.c:6347-6358).

Reachability and Preconditions

  • The sniffer is built in, is watching the connection, and has recovery enabled.
  • A segment of one or two payload bytes is on the reassembly list for one direction. The sender of that direction controls segment size, payload and sequence number, so a TLS client or server on the monitored connection can supply it. Its first byte must be 0x17. No TLS authentication is involved; TCP payload is enough.
  • The scan for that direction must be armed. That needs a packet in the opposite direction that acknowledges data the sniffer did not capture: a real capture gap, or a party able to place such a packet in the capture. On a capture with no gaps, the sender of the short segment cannot arm the scan for its own direction alone; the peer's acknowledgement has to run ahead of what the sniffer has processed.

Impact

A read of one byte, at most two, past the end of a one- or two-byte heap allocation in the process running the sniffer. The value is used only in an equality test. It is not copied, logged or returned, so nothing is disclosed. A crash requires the byte after the allocation to be unmapped, which is not the case for small blocks on ordinary heap allocators. Memory-checking builds report the access. A crash, where it happens, stops traffic monitoring; it does not affect the monitored TLS endpoints.

ByteRay did not build a proof of concept for this issue. The analysis is from source review. The public issue and the upstream pull request that fixed it each report a reproduction under AddressSanitizer: a heap-buffer-overflow read of size 1 directly after a 2-byte region in FindNextRecordInAssembly, and, in the pull request, a clean run of the same capture after the change. Those reproductions are theirs, not ByteRay's.

Remediation and Mitigation

Fixed on master by commit 59179e8239cec5b4f7c5553b1149f765bcd173be (PR 12195, merged 2026-11-20). The comparison is now preceded by a test that the buffer holds at least three bytes, the record type plus the two version bytes. Shorter buffers fall through to the existing path that drops them. The fix is on master only. No release contains it as of 2026-12-03.

Until a release does, leave recovery disabled, which is the default. With recovery off, an acknowledgement for unseen data ends the session with an error instead of starting the scan. The cost is that sessions with capture gaps are no longer decoded.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-11-18 — The same defect was reported publicly, by an independent third party, in wolfSSL issue 12171.
  • 2026-11-19 — Pull request 12195 opened upstream. Its description says it fixes issue 12171.
  • 2026-11-20 — Pull request 12195 merged to master.
  • 2026-12-03 — Public disclosure.

Credits

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

References