wolfSSL — Heap Out-of-Bounds Read in Sniffer Certificate Message Parser
The sniffer's Certificate handler advances past the 3-byte certificate length without reducing its remaining-byte count. The following length check accepts a certificate size up to 3 bytes larger than the data present, and the watch-mode code hashes that span, reading up to 3 bytes past the heap input buffer.
- Advisory
- BYTERAY-2026-0475
- 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 (tested at master commit d95483f), sniffer builds with WOLFSSL_SNIFFER_WATCH and a registered watch callback
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
In watch mode (WOLFSSL_SNIFFER_WATCH) the wolfSSL sniffer parses the server's Certificate message, hashes the first certificate with SHA-256 and passes it to the operator's watch callback. ProcessCertificate() in src/sniffer.c does the parsing.
The function tracks its position with a pointer and a count of remaining bytes. For the outer chain length it moves both. For the inner certificate length it moves the pointer by 3 bytes and leaves the count unchanged. The check that follows compares the declared certificate size with a count that is 3 bytes too large.
A server endpoint of a monitored session can send a Certificate message whose declared certificate size is up to 3 bytes larger than the data that follows. The sniffer hashes that span and hands it to the callback. When the message ends at the end of the sniffer's exactly sized heap input buffer, the read crosses the allocation. The bytes go only into a local digest and the operator's own callback, so nothing is disclosed to the attacker. The consequence is a possible crash of the sniffer. Watch mode is not part of a default build.
Affected Products and Versions
- Component:
src/sniffer.c,ProcessCertificate()andKeyWatchCall(). - Required build: the sniffer with
WOLFSSL_SNIFFER_WATCH. The certificate case inDoHandShake()is compiled only with that option (src/sniffer.c:5073-5075). A watch callback must be registered withssl_SetKeyWatchCallback(). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include the sniffer (configure.ac:3161-3162). - Other releases were not checked.
Technical Details
The outer header is handled with a paired decrement and advance (src/sniffer.c:4754-4756). The inner header is not (src/sniffer.c:4767-4769):
ato24(input, &certChainSz);
*sslBytes -= CERT_HEADER_SZ;
input += CERT_HEADER_SZ;
...
ato24(input, &certSz);
input += OPAQUE24_LEN;
if (*sslBytes < (int)certSz) {
*sslBytes -= OPAQUE24_LEN is missing at src/sniffer.c:4768. The guard at src/sniffer.c:4769 therefore admits a certSz up to 3 bytes beyond the data left at the advanced pointer.
ssl_DecodePacketInternal()(src/sniffer.c:7112) takes the captured TCP payload. The remote server controls the declared sizes, the bytes present and the segment boundaries.- A record that spans TCP segments is accumulated in the sniffer's heap input buffer (
src/sniffer.c:6722-6740). The buffer is grown to the size requested with no padding for TCP (src/internal.c:12800), so the data can end exactly at the allocation end. A complete record in one segment is parsed in place from the capture buffer and does not reach the heap boundary. DoHandShake()callsProcessCertificate()for the certificate message. Only the server-to-client direction proceeds (src/sniffer.c:4734).- The stale guard passes and
KeyWatchCall()is called withcertSz(src/sniffer.c:4776). KeyWatchCall()runswc_Sha256Update()overcertSzbytes (src/sniffer.c:4700) and passes the same span to the watch callback (src/sniffer.c:4708-4709). Both read up to 3 bytes past the valid data.
If no watch callback is registered, KeyWatchCall() returns before any read (src/sniffer.c:4693-4696). TLS 1.2 Certificate messages are plaintext. TLS 1.3 Certificate messages are decrypted with the handshake keys the sniffer already holds.
Reachability and Preconditions
- Build and runtime: sniffer with
WOLFSSL_SNIFFER_WATCH, which is not a default configuration. A watch callback is installed, and the session is tracked by the sniffer. - Attacker position: the server endpoint of a monitored TLS session, or anyone who can inject server-to-client bytes into it. No authentication is needed.
- The crafted Certificate message must be the last data in the accumulated input buffer, so that the extra 3 bytes fall outside the allocation. A crash also requires the allocation to end on a page boundary.
Impact
A heap out-of-bounds read of up to 3 bytes past the sniffer's input buffer, triggered remotely. If the read crosses into an unmapped page the monitoring process crashes. There is no information disclosure to the attacker: the bytes are folded into a SHA-256 digest and passed to the operator's own callback. The build option, the callback and the buffer alignment together make a reliable trigger difficult.
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 reduce *sslBytes by OPAQUE24_LEN where the pointer is advanced past the inner certificate length, as the outer header handling does. Every pointer advance in the sniffer's handshake parsers should have a matching decrement. Computing the message end once and checking input + certSz against it before any read would remove the need to keep two values in step. Workaround: build the sniffer without WOLFSSL_SNIFFER_WATCH if watch mode is not used.
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.