wolfSSL — Corrupted TLS 1.3 Records and Send Loop Hang in Threaded Record Encryption
With WOLFSSL_THREADED_CRYPT, application records are handed to worker threads for encryption. The TLS 1.3 record builder has no such handoff and encrypts inline, but the send path still queues the finished record as a TLS 1.2 job. With AES-GCM the worker corrupts the record before it is sent; with other suites the record is never sent and the seventeenth write spins forever.
- Advisory
- BYTERAY-2026-0340
- CWE
- CWE-704
- CVSS
- 6.5 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:H)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, builds with WOLFSSL_THREADED_CRYPT on connections that negotiate TLS 1.3
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
WOLFSSL_THREADED_CRYPT moves bulk encryption of application data to threads owned by the application. wolfSSL_write() builds the record without encrypting it, parks it in one of 16 job slots and returns. A worker thread calls wolfSSL_AsyncEncrypt() on the slot, and a later call into the library sends the result.
That design is implemented for TLS 1.2 only. For a TLS 1.3 connection the send path calls BuildTls13Message(), which encrypts the record itself, and then queues the already encrypted record for the worker as if it were a TLS 1.2 plaintext record. On an AES-GCM suite the worker's encryption call fails, the worker overwrites eight bytes of the record anyway, marks the job done, and the damaged record is sent. On any other suite the worker does nothing, the job is never marked done, and the slot is never released.
The result is that TLS 1.3 application data does not work in these builds, and a peer that negotiates TLS 1.3 with a non-GCM suite leaves the writing thread in a busy loop. Default builds are not affected: no configure option sets WOLFSSL_THREADED_CRYPT.
Affected Products and Versions
- Component: TLS record sending,
SendData()andSendAsyncData()insrc/internal.c,BuildTls13Message()insrc/tls13.c,wolfSSL_AsyncEncrypt()insrc/ssl.c. - Required build:
WOLFSSL_THREADED_CRYPT, defined by the integrator, with TLS 1.3 enabled (the default). The macro is not set byconfigure.acor the CMake build. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same code. - Not fixed on master.
- A default
./configurebuild does not compile this code. Earlier releases were not checked.
Technical Details
For TLS 1.2, BuildMessage() returns before the encryption step when the caller allows deferred encryption (src/internal.c:27512-27531). SendData() relies on that. For TLS 1.3 it takes the other branch (src/internal.c:29776-29779):
else {
#ifdef WOLFSSL_TLS13
sendSz = BuildTls13Message(ssl, out, outputSz, sendBuffer, buffSz,
application_data, 0, 0, 1);
out is the job slot's buffer. src/tls13.c contains no WOLFSSL_THREADED_CRYPT code. BuildTls13Message() treats its last argument as a hardware-async hint only and encrypts in place with the connection's own cipher (src/tls13.c:3608-3612). SendData() then stages the slot exactly as for TLS 1.2 (src/internal.c:29793-29838): it sets up a per-slot cipher with SetKeys(), fills TLS 1.2 additional data, signals the worker and returns the record size to the caller.
The worker (src/ssl.c:10449-10483) acts only when the suite is AES-GCM (src/ssl.c:10454). It ends with (src/ssl.c:10474-10479):
#if !defined(NO_PUBLIC_GCM_SET_IV) && \
((!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
XMEMCPY(out, encrypt->nonce + AESGCM_IMP_IV_SZ, AESGCM_EXP_IV_SZ);
#endif
encrypt->done = 1;
What happens to a TLS 1.3 record:
- AES-GCM suite.
SetKeys()arms the AES-GCM IV generator only for TLS 1.2 (src/keys.c:2731-2739), so the slot's AES object has no nonce size. The worker'swc_AesGcmEncrypt_ex()call rejects the request withBAD_FUNC_ARGand writes nothing (wolfcrypt/src/aes.c:15152-15157). - The copy shown above runs regardless. It replaces the first eight bytes after the record header, which are TLS 1.3 ciphertext, with part of the slot's nonce field. In this build nothing fills that field.
doneis set regardless of the result.SendAsyncData()copies the slot to the output buffer and sends it (src/internal.c:29339-29349). The peer cannot authenticate the record.- Any other suite. The worker returns
NOT_COMPILED_IN(src/ssl.c:10451) and never setsdone. The slot stays reserved and the record is never sent, althoughwolfSSL_write()already reported success for it (src/internal.c:29838). - After 16 such writes (
wolfssl/ssl.h:4151-4163) no slot is free. The next write enters this loop (src/internal.c:29720-29735), whereSendAsyncData()finds no finished job and returns 0, so the loop never exits:
do {
for (i = 0; i < WOLFSSL_THREADED_CRYPT_CNT; i++) {
if (ssl->buffers.encrypt[i].avail) {
encrypt = &ssl->buffers.encrypt[i];
break;
}
}
if (encrypt == NULL) {
ret = SendAsyncData(ssl);
Builds that select the plain wc_AesGcmEncrypt() call in the worker (src/ssl.c:10460-10466) take a different path in step 1; ByteRay did not analyse that variant further.
Reachability and Preconditions
- The library is built with
WOLFSSL_THREADED_CRYPT. Nothing in the build system, tests or examples of the tested tree enables it. - The connection negotiates TLS 1.3. Either side of the connection is affected when it sends application data.
- For the busy loop, the negotiated suite is not AES-GCM (for example ChaCha20-Poly1305 or AES-CCM) and the application writes at least 17 records.
- A remote peer needs no credentials: offering or selecting TLS 1.3 is enough.
- The worker handles AES-GCM only and
BuildMessage()defers encryption for every suite, so a TLS 1.2 connection on a non-GCM suite exhausts the slots in the same way.
Impact
Confirmed from the source: on AES-GCM suites every TLS 1.3 application record leaves the endpoint with eight bytes overwritten, the peer's record authentication fails, and the connection is lost. On other suites application data is silently not sent and the writing thread spins without returning once the slots run out, which holds a thread and a processor core for each such connection.
The corrupted record is rejected by a correct peer, so this is not a way to deliver modified plaintext. ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03). A fix either gives TLS 1.3 a real deferred-encryption path, or makes the send path bypass the job slots for TLS 1.3 and send the inline-encrypted record directly. Independently, the slot search should fail rather than loop when no job can complete, and a worker that cannot process a job should release it with an error.
Until then, integrators who use WOLFSSL_THREADED_CRYPT should restrict the build or the context to TLS 1.2 with AES-GCM suites. The cost is losing TLS 1.3 on those endpoints.
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
- SendData threaded staging at the tested commit
- wolfSSL_AsyncEncrypt at the tested commit
- BuildTls13Message inline encryption at the tested commit
- BYTERAY-2026-0341: job lifecycle races in threaded record encryption
- BYTERAY-2026-0342: worker API index and failure handling
- CWE-704: Incorrect Type Conversion or Cast