wolfSSL — Unchecked Job Index and Ignored Encryption Failure in the Threaded Encryption Worker API
The four WOLFSSL_THREADED_CRYPT worker functions index a 16-entry job array with a caller-supplied value that is never range-checked. wolfSSL_AsyncEncrypt also marks a job done whatever the AES-GCM call returns, so when key setup or encryption fails the record is transmitted with its plaintext still in place.
- Advisory
- BYTERAY-2026-0342
- CWE
- CWE-704
- CVSS
- 6.9 (CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:H/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
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
In a WOLFSSL_THREADED_CRYPT build the application's worker threads drive record encryption through four public functions that take a WOLFSSL pointer and a job index. None of them checks the index against the size of the job array, and one of them does not check the pointer.
The more serious defect is in wolfSSL_AsyncEncrypt(). It calls AES-GCM on the job buffer and then marks the job done without looking at the result. The record in the buffer was built without encryption, so if the AES-GCM call fails the bytes that get sent are the record header, an explicit IV and the application's plaintext. One way to make the call fail needs no misuse by the application: the send path ignores an error from the slot's key setup and still marks the slot initialised.
Default builds are not affected: no configure option sets WOLFSSL_THREADED_CRYPT. A network peer does not choose the index and cannot directly cause the failure.
Affected Products and Versions
- Component:
wolfSSL_AsyncEncryptReady(),wolfSSL_AsyncEncryptStop(),wolfSSL_AsyncEncrypt()andwolfSSL_AsyncEncryptSetSignal()insrc/ssl.c; slot key setup inSendData()insrc/internal.c. - Required build:
WOLFSSL_THREADED_CRYPT, defined by the integrator. 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
The job array has WOLFSSL_THREADED_CRYPT_CNT entries, 16 by default (wolfssl/ssl.h:4151-4163, wolfssl/internal.h:5318-5320). Each worker function uses idx directly. wolfSSL_AsyncEncryptReady() and wolfSSL_AsyncEncryptStop() read through it (src/ssl.c:10433, src/ssl.c:10445). wolfSSL_AsyncEncryptSetSignal() writes two pointers through it (src/ssl.c:10494-10495):
ssl->buffers.encrypt[idx].signal = signal;
ssl->buffers.encrypt[idx].signalCtx = ctx;
An index outside 0 to 15 addresses memory before or after the array inside the WOLFSSL object, or outside the object.
wolfSSL_AsyncEncrypt() (src/ssl.c:10449-10483) begins:
int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
ThreadCrypt* encrypt = &ssl->buffers.encrypt[idx];
if (ssl->specs.bulk_cipher_algorithm == wolfssl_aes_gcm) {
unsigned char* out = encrypt->buffer.buffer + encrypt->offset;
unsigned char* input = encrypt->buffer.buffer + encrypt->offset;
word32 encSz = encrypt->buffer.length - encrypt->offset;
There is no NULL check on ssl, unlike the other three functions. The length passed to AES-GCM is encSz - AESGCM_EXP_IV_SZ - ssl->specs.aead_mac_size (src/ssl.c:10469), an unsigned subtraction that wraps to a very large value when the slot has no staged record. After the AES-GCM call the function copies the explicit IV into the record and sets encrypt->done = 1 without testing ret (src/ssl.c:10474-10479).
How a failed call puts plaintext on the wire:
- For these records
BuildMessage()returns before encrypting (src/internal.c:27512-27531). The job buffer holds the header, room for the explicit IV, the plaintext and room for the tag. - On first use of a slot
SendData()callsSetKeys()for the slot's cipher, discards the return value and setsinit(src/internal.c:29794-29799). IfSetKeys()fails, for example on the allocation atsrc/keys.c:2690-2692, the slot's AES pointer stays NULL and the slot is never set up again. - The worker calls
wc_AesGcmEncrypt_ex()with that pointer. It returnsBAD_FUNC_ARGand writes nothing (wolfcrypt/src/aes.c:15152-15157). - The worker sets
done.SendAsyncData()copies the job buffer to the output buffer and sends it (src/internal.c:29339-29349). - Every later record that uses the same slot goes the same way.
Reachability and Preconditions
- The library is built with
WOLFSSL_THREADED_CRYPT. The worker acts only on AES-GCM suites, and the plaintext case applies to TLS 1.2, where the queued record is not yet encrypted. - Out-of-range access needs the application to pass an index outside 0 to 15, for example by sizing its worker pool from a different constant. The index does not come from the network.
- The wrapped length needs a worker to call
wolfSSL_AsyncEncrypt()on a slot that has not been staged. BYTERAY-2026-0341 describes a window in which the library itself reports such a slot as ready. - Plaintext transmission needs the AES-GCM call to fail. The verified route is a failed slot key setup, which in practice means memory exhaustion at the moment a slot is first used.
- A network peer cannot trigger these directly. A local party able to exhaust the process's memory can make the failure more likely.
Impact
Confirmed from the source: when the worker's AES-GCM call fails, application data is sent unencrypted and unauthenticated inside a record marked as protected, and this repeats for every record assigned to the affected slot. The peer rejects such records, so the connection fails, but an observer on the path has already seen the plaintext.
The index and NULL defects are missing argument checks in a public API; with a wrong index wolfSSL_AsyncEncryptSetSignal() overwrites two pointer-sized fields at a location fixed by that index, and the other functions read or operate on unrelated memory. 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 validates ssl and idx in all four functions, refuses to process a slot with no staged record, and marks a job done only when encryption succeeded; on failure the job must be discarded and the error reported to the connection so that nothing is sent. The send path must also check the result of the slot's key setup before marking the slot initialised.
Applications that use this feature should derive their worker count from WOLFSSL_THREADED_CRYPT_CNT, check the return value of wolfSSL_AsyncEncrypt(), and close the connection when it is non-zero. Checking the return value does not stop the record from being sent, because the job is already marked done.
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.