← ALL ADVISORIES

MEDIUM BYTERAY-2026-0385Disclosed

wolfSSL — Endless Shutdown Retry on Encrypt-then-MAC Failure in TLS Record Processing

When an Encrypt-then-MAC record fails its MAC check on a TCP connection, wolfSSL returns an error without consuming the record or resetting the record state machine. wolfSSL_shutdown then reports this permanent failure as WOLFSSL_SHUTDOWN_NOT_DONE, so an application that follows the documented retry loop calls it forever.

Advisory
BYTERAY-2026-0385
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 with a CBC cipher suite and Encrypt-then-MAC negotiated (default builds)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

DoProcessReplyEx() in src/internal.c is the TLS record receiver. It works through a record in stages and keeps the current stage in ssl->options.processReply. With the Encrypt-then-MAC extension negotiated, it checks the record MAC over the ciphertext before it decrypts.

When that check fails on a TCP connection, the function returns DECRYPT_ERROR and changes nothing else. The read index of the input buffer still points at the failed record, and the stage is still the MAC check. The next call verifies the same bytes and fails the same way.

wolfSSL_shutdown() turns this into a hang. It does not store the record error in ssl->error, so it reports the failure as WOLFSSL_SHUTDOWN_NOT_DONE, the value its documentation says to retry on. A peer or on-path attacker who delivers one corrupted record where close_notify is expected makes a compliant application loop without end. CBC suites and Encrypt-then-MAC are enabled in default builds.

Affected Products and Versions

  • Component: src/internal.c, DoProcessReplyEx(), the verifyEncryptedMessage stage. It is reached at shutdown through wolfssl_shutdown_recv_close_notify() in src/ssl_api_rw.c.
  • Required build: HAVE_ENCRYPT_THEN_MAC without WOLFSSL_AEAD_ONLY, and a CBC cipher suite. The Encrypt-then-MAC extension is enabled by default (configure.ac:10387).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • Default builds are affected. DTLS is not: that path drops the datagram and resets the receiver.
  • Other releases were not checked.

Technical Details

The stage is entered at src/internal.c:25895. VerifyMacEnc() checks the MAC over the buffered record (src/internal.c:25903-25905). The failure handling is at src/internal.c:25910-25926. For a TCP connection it ends with:

                #ifdef WOLFSSL_EXTRA_ALERTS
                    if (!ssl->options.dtls)
                        SendAlert(ssl, alert_fatal, bad_record_mac);
                #endif
                    WOLFSSL_ERROR_VERBOSE(DECRYPT_ERROR);
                    return DECRYPT_ERROR;

The DTLS branch calls DropAndRestartProcessReply() (src/internal.c:25916). The TCP branch has no counterpart. It does not advance ssl->buffers.inputBuffer.idx past the record and does not reset ssl->options.processReply. The bad_record_mac alert is compiled only with WOLFSSL_EXTRA_ALERTS (src/internal.c:25920-25923), which a default build does not define, and the specific cause is replaced with the generic DECRYPT_ERROR (src/internal.c:25924-25925).

How the failure becomes a loop at shutdown:

  1. The application calls wolfSSL_shutdown(), which reaches wolfssl_shutdown_recv_close_notify() (src/ssl_api_rw.c:990). That function calls ProcessReply() and keeps the result in a local variable only (src/ssl_api_rw.c:1004). ssl->error is not written.
  2. DoProcessReplyEx() runs VerifyMacEnc() on the buffered record, fails, and returns DECRYPT_ERROR with the read index and stage unchanged.
  3. ssl->error is still zero, so the branch at src/ssl_api_rw.c:1020-1022 returns WOLFSSL_SHUTDOWN_NOT_DONE.
  4. The function comment tells callers to call again while that value is returned (src/ssl_api_rw.c:1032-1035). Each call repeats steps 1 to 3 on the same bytes.

Reachability and Preconditions

  • Build: Encrypt-then-MAC and at least one CBC suite compiled in, which is the default.
  • Runtime: a TLS connection over TCP that negotiated a CBC suite with Encrypt-then-MAC. The peer influences this choice during negotiation.
  • Application: calls wolfSSL_shutdown() repeatedly while it returns WOLFSSL_SHUTDOWN_NOT_DONE, as documented, with no bound of its own.
  • Attacker position: the TLS peer, or an on-path attacker who can corrupt or replay one encrypted record at shutdown time. No credentials and no user interaction are needed.

Impact

Denial of service. The thread that services the connection spins in the shutdown loop at full CPU until something outside the loop stops it. There is no confidentiality or integrity impact. In a default build no bad_record_mac alert is sent from this site, so the peer side sees no signal either. The loop runs in the application's retry code, not inside wolfSSL. An application that bounds its shutdown retries is not held.

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 TCP path, drop the failed record and reset the stage machine on MAC failure, as the DTLS path does. Send the fatal bad_record_mac alert without a build option and keep the specific error cause. In the shutdown path, store the fatal cause in ssl->error and return WOLFSSL_SHUTDOWN_NOT_DONE only for conditions that can change on retry. 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.

References