← ALL ADVISORIES

LOW BYTERAY-2026-0490Disclosed

wolfSSL — Unchecked Short Read in AF_ALG AES-CBC Encryption Reports Success and Corrupts the Next IV

In the Linux AF_ALG port, wc_AesCbcEncrypt reads the ciphertext from the kernel crypto socket with one read() and treats only a negative return as an error. After a zero or short read it reports success and copies the next chaining IV from the stale tail of the output buffer.

Advisory
BYTERAY-2026-0490
CWE
CWE-252
CVSS
3.6 (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with WOLFSSL_AFALG (--enable-afalg) and HAVE_AES_CBC
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The AF_ALG port sends AES operations to the Linux kernel crypto API over a socket. wc_AesCbcEncrypt() submits the plaintext with sendmsg() and reads the ciphertext back with a single read().

Both calls are checked only for a negative return. If the kernel returns zero bytes, or fewer bytes than requested, the output buffer is left wholly or partly unchanged and the function still returns 0. It also copies the IV for the next call from the last block of that buffer, so one short read corrupts the current output and the chaining state of the operations that follow.

Another function in the same file, wc_Afalg_AesDirect(), checks for a short transfer and loops on the read. The CBC routines do not. A remote peer does not control the kernel's return value, and the AF_ALG port is off in a default build.

Affected Products and Versions

  • Component: wolfcrypt/src/port/af_alg/afalg_aes.c, wc_AesCbcEncrypt().
  • Required build: WOLFSSL_AFALG (wolfcrypt/src/port/af_alg/afalg_aes.c:24) with HAVE_AES_CBC (wolfcrypt/src/port/af_alg/afalg_aes.c:184). --enable-afalg defines WOLFSSL_AFALG (configure.ac:5049-5057).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build does not include this code.
  • Other releases were not checked.

Technical Details

The transfer and the IV update are at wolfcrypt/src/port/af_alg/afalg_aes.c:241-251. The sendmsg() call just above the read has the same form of check. The read and the IV update:

            ret = (int)read(aes->rdFd, out, sz);
            if (ret < 0) {
                return WC_AFALG_SOCK_E;
            }
            /* set IV for next CBC call */
            XMEMCPY(aes->reg, out + sz - WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);

Data flow:

  1. sendmsg() submits the request (wolfcrypt/src/port/af_alg/afalg_aes.c:241). A return smaller than sz is not detected.
  2. read() asks for sz bytes of ciphertext (wolfcrypt/src/port/af_alg/afalg_aes.c:245). A return of zero, or of fewer than sz bytes, is not detected.
  3. The last block of out is copied into aes->reg as the next IV, however many bytes were actually written (wolfcrypt/src/port/af_alg/afalg_aes.c:251).
  4. The function returns 0 (wolfcrypt/src/port/af_alg/afalg_aes.c:254).

wc_Afalg_AesDirect() shows the intended contract. It rejects a sendmsg() return that differs from sz (wolfcrypt/src/port/af_alg/afalg_aes.c:373-376) and reads in a loop that fails on ret <= 0 (wolfcrypt/src/port/af_alg/afalg_aes.c:380-385). The decrypt routine has the same unchecked pair of calls. It is described in BYTERAY-2026-0489.

Reachability and Preconditions

  • The library is built with WOLFSSL_AFALG and AES-CBC.
  • The caller encrypts through wc_AesCbcEncrypt(): a TLS CBC cipher suite or application code.
  • The kernel cbc(aes) transform returns zero or fewer bytes than requested. This is a local system condition. Input from a remote peer cannot force it, and it was not shown in practice. No authentication state is involved.

Impact

Stale or partial ciphertext is reported as a successful encryption, and the IV taken from it carries the error into later calls on the same key object. In TLS the peer rejects the damaged records and the connection fails. In application use the stored or transmitted ciphertext is wrong without any error. No confidentiality impact is identified.

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 apply the handling in wc_Afalg_AesDirect() to this function: require sendmsg() to accept the full length, read in a loop that fails on any non-positive return, and copy the next IV into aes->reg only after the whole output has been read. The decrypt routine needs the same change. Builds without WOLFSSL_AFALG use the software or other hardware AES paths and are not affected.

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