wolfSSL — Unconsumed Record After AEAD Decrypt Failure Causes Endless wolfSSL_shutdown Retry
When record decryption fails on a TLS stream, DoProcessReplyEx returns without consuming the record or resetting its state. During shutdown the failure is not stored in ssl->error, so wolfSSL_shutdown reports the retryable WOLFSSL_SHUTDOWN_NOT_DONE and each retry fails on the same record and queues another alert.
- Advisory
- BYTERAY-2026-0384
- CWE
- CWE-544
- CVSS
- 5.9 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), all builds; TLS over stream transports, in applications that call wolfSSL_shutdown again while it returns WOLFSSL_SHUTDOWN_NOT_DONE
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_shutdown() is documented to be called repeatedly while it returns WOLFSSL_SHUTDOWN_NOT_DONE. To wait for the peer's close_notify, it calls ProcessReply(), which runs the record state machine in DoProcessReplyEx().
If an incoming record fails authenticated decryption, the TLS path in DoProcessReplyEx() sends a bad_record_mac alert and returns the error. It does not move the input buffer past the record and does not reset the processing stage. The next call starts in the decrypt stage on the same bytes and fails again. The shutdown code does not store the ProcessReply() result in ssl->error, so it maps this permanent failure to WOLFSSL_SHUTDOWN_NOT_DONE.
An application that follows the documented contract then loops without end on one corrupted record, using a full CPU core on the thread that serves the connection. Each pass also queues another alert record, so pending output grows when the transport is not draining. One flipped ciphertext byte is enough with the default AEAD suites. No build option is involved, so default builds are affected.
Affected Products and Versions
- Component:
src/internal.c,DoProcessReplyEx(), the decrypt failure path;src/ssl_api_rw.c,wolfssl_shutdown_recv_close_notify(). - Required build: none. The DTLS path is handled differently and is not affected.
- Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild is affected. - Other releases were not checked.
Technical Details
The TLS decrypt failure path ends at src/internal.c:26006-26009:
SendAlert(ssl, alert_fatal, bad_record_mac);
/* Push error once we know that we will error out here */
WOLFSSL_ERROR(ret);
return ret;
The loop:
- The application calls
wolfSSL_shutdown(), which callswolfssl_shutdown_internal()(src/ssl_api_rw.c:1064-1066). wolfssl_shutdown_recv_close_notify()runsret = ProcessReply(ssl);and keeps the result in a local variable only (src/ssl_api_rw.c:1004).ProcessReply()reachesDoProcessReplyEx()(src/internal.c:26515-26518). The state machine setsssl->options.processReply = decryptMessage(src/internal.c:25930) and callsDoDecrypt()(src/internal.c:25940).- Decryption fails on the AEAD tag. The failure path (
src/internal.c:25963-26009) sendsbad_record_macand returns.ssl->buffers.inputBuffer.idxis not advanced andprocessReplystays atdecryptMessage. - Back in the shutdown code,
ssl->erroris stillWOLFSSL_ERROR_NONE, so the branch atsrc/ssl_api_rw.c:1020-1022returnsWOLFSSL_SHUTDOWN_NOT_DONE. - The application calls again, as the documentation says (
src/ssl_api_rw.c:1032-1035). Step 3 resumes incase decryptMessage(src/internal.c:25934) on the same record and fails the same way.
For DTLS the same failure path calls DropAndRestartProcessReply() (src/internal.c:25969), which resets the stage and empties the input buffer (src/internal.c:25217-25226). The TLS path has no equivalent step. The SendAlert() call at src/internal.c:26006 is not behind a build flag, so every pass appends an alert record to the output buffer. The same retry mechanism with a different failing stage is described in BYTERAY-2026-0385. The missing ssl->error store in the shutdown code is described in BYTERAY-2026-0386.
Reachability and Preconditions
- No build flag is required.
- An established TLS session over a stream transport. The default AEAD suites, AES-GCM and ChaCha20-Poly1305, fail deterministically on any modified ciphertext.
- The application calls
wolfSSL_shutdown()in a loop while it returnsWOLFSSL_SHUTDOWN_NOT_DONE, without a retry limit. - The attacker is the TLS peer, or a party on the network path able to change one byte of a record in flight. The corrupted record has to be the one the endpoint reads during shutdown, and no
close_notifyfollows. A peer needs whatever authentication the session required. A party on the path needs none.
Impact
A single corrupted record can hold the thread that serves the connection in an endless loop at full CPU use. A few such connections can exhaust a thread pool. When the transport is backpressured, the alert records queued on each pass are not drained and the pending output grows without a bound, which adds memory exhaustion to the CPU load. The effect is denial of service. There is no confidentiality or integrity effect.
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 has three parts. On the TLS decrypt failure path, consume the failed record and reset ssl->options.processReply before returning, as the DTLS path does, so that a later ProcessReply() cannot process the same bytes again. In wolfssl_shutdown_recv_close_notify(), store the ProcessReply() result in ssl->error so that a permanent failure is not reported as WOLFSSL_SHUTDOWN_NOT_DONE. Treat a decrypt failure as final for the shutdown sequence, so that repeated failures cannot queue more alert records. Application-side mitigation: put a limit on the number of wolfSSL_shutdown() retries, or a deadline, and close the socket when it is reached.
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.