wolfSSL — Missing Error Store in wolfSSL_shutdown close_notify Receive Path
The function that waits for the peer's close_notify during wolfSSL_shutdown does not store the record-processing result in ssl->error. A permanent record failure, such as a failed MAC check, is returned as WOLFSSL_SHUTDOWN_NOT_DONE, and the failed record stays in the input buffer, so the documented retry loop never ends.
- Advisory
- BYTERAY-2026-0386
- 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), TLS over TCP, applications that retry wolfSSL_shutdown while it returns WOLFSSL_SHUTDOWN_NOT_DONE (default builds)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_shutdown() waits for the peer's close_notify in wolfssl_shutdown_recv_close_notify() (src/ssl_api_rw.c). The documentation tells applications to call wolfSSL_shutdown() again while it returns WOLFSSL_SHUTDOWN_NOT_DONE.
The function calls ProcessReply() and keeps the result in a local variable. It never copies it to ssl->error. That field was cleared when the handshake finished, so after a hard record error it still reads "no error", and the function maps the failure to WOLFSSL_SHUTDOWN_NOT_DONE. On TCP the record layer does not consume a record that failed authentication, so every retry fails on the same bytes.
One corrupted encrypted record from the peer, or from an on-path attacker, in place of close_notify keeps a compliant application in its shutdown loop indefinitely. Default builds are affected. A second defect in the same function: an out-of-memory result returns WOLFSSL_FATAL_ERROR with no cause stored, so wolfSSL_get_error() reports a stale value.
Affected Products and Versions
- Component:
src/ssl_api_rw.c,wolfssl_shutdown_recv_close_notify(), called fromwolfSSL_shutdown(). - Required build: none beyond TLS over TCP. No build option gates the loop.
- Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- Default builds are affected. On DTLS the record layer drops a datagram that fails authentication, so the same record is not seen again.
- Other releases were not checked.
Technical Details
The result handling is at src/ssl_api_rw.c:1004-1022:
ret = ProcessReply(ssl);
...
else if (ssl->error == WOLFSSL_ERROR_NONE) {
ret = WOLFSSL_SHUTDOWN_NOT_DONE;
}
Only WANT_READ is stored (src/ssl_api_rw.c:1017). The MEMORY_E branch returns a fatal error with nothing in ssl->error (src/ssl_api_rw.c:1013-1015). Any other error reaches the last branch with ssl->error still zero and becomes WOLFSSL_SHUTDOWN_NOT_DONE (src/ssl_api_rw.c:1020-1022).
How one record becomes a loop:
wolfSSL_shutdown()(src/ssl_api_rw.c:1064-1066) reacheswolfssl_shutdown_recv_close_notify()(src/ssl_api_rw.c:990), which callsProcessReply().- In
DoProcessReplyEx(),VerifyMac()fails over the peer's record and the function returnsDECRYPT_ERROR(src/internal.c:26028-26051). The input buffer index andssl->options.processReplyare unchanged. - The
bad_record_macalert at that site is compiled only withWOLFSSL_EXTRA_ALERTSand withoutWOLFSSL_NO_ETM_ALERT(src/internal.c:26045-26048). A default build sends nothing.DropAndRestartProcessReply()resets the receiver for DTLS only (src/internal.c:26040-26042). TLS has no counterpart. - Back in the shutdown function
ssl->erroris zero, so the caller getsWOLFSSL_SHUTDOWN_NOT_DONEand, following the comment atsrc/ssl_api_rw.c:1032-1035, calls again. The entry guard inDoProcessReplyEx()that refuses to run in an error state (src/internal.c:25566-25583) does not fire, becausessl->erroris zero.
The Encrypt-then-MAC failure site (src/internal.c:25925) behaves the same way and is described in BYTERAY-2026-0385. The AEAD decrypt site is described in BYTERAY-2026-0384.
Reachability and Preconditions
- Build and runtime: a default build, and an established TLS session over TCP, so that records are encrypted and authenticated.
- Application: calls
wolfSSL_shutdown()again while it returnsWOLFSSL_SHUTDOWN_NOT_DONE, as documented, with no bound of its own. - Attacker position: the TLS peer, or an on-path attacker who can flip one ciphertext byte of a record in flight. The peer withholds
close_notify. No further authentication is needed.
Impact
Denial of service from a single record. The thread that services the connection re-verifies the same buffered bytes on every call, with no system calls in between, and runs at full CPU until an operator intervenes. A small number of such connections can exhaust a thread pool. The loop runs in the application's documented retry code, which is why attack complexity is rated high. Separately, callers that ask wolfSSL_get_error() for the reason after the out-of-memory return receive a stale value.
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 store the result of ProcessReply() in ssl->error right after the call, to return WOLFSSL_SHUTDOWN_NOT_DONE only for want-read and want-write conditions, and to return WOLFSSL_FATAL_ERROR with the cause recorded for permanent failures including MEMORY_E. The TLS record path should also drop or skip a record that failed authentication, as the DTLS path does, so that a retry makes progress. Workaround: bound the shutdown loop in the application with a retry count or a deadline, and close the socket when the bound 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.