wolfSSL — Unchecked Short Read in AF_ALG AES-CBC Decryption Returns Stale Output as Plaintext
In the Linux AF_ALG port, wc_AesCbcDecrypt reads the plaintext from the kernel crypto socket with one read() and treats only a negative return as an error. A zero or short read leaves the output buffer wholly or partly unchanged and the function still returns success.
- Advisory
- BYTERAY-2026-0489
- 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), HAVE_AES_CBC and AES decryption
- 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_AesCbcDecrypt() submits the ciphertext with sendmsg() and reads the plaintext 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 function returns 0. The caller then uses whatever was already in the output buffer as decrypted data. Another function in the same file, wc_Afalg_AesDirect(), checks for a short transfer and loops on the read, so the CBC path is inconsistent with the port's own handling.
The condition is a degenerate return from the kernel crypto provider. A remote peer does not control it. The AF_ALG port is off in a default build.
Affected Products and Versions
- Component:
wolfcrypt/src/port/af_alg/afalg_aes.c,wc_AesCbcDecrypt(). - Required build:
WOLFSSL_AFALG(wolfcrypt/src/port/af_alg/afalg_aes.c:24) withHAVE_AES_CBC(wolfcrypt/src/port/af_alg/afalg_aes.c:184) andHAVE_AES_DECRYPT.--enable-afalgdefinesWOLFSSL_AFALG(configure.ac:5049-5057). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include this code. - Other releases were not checked.
Technical Details
The transfer is at wolfcrypt/src/port/af_alg/afalg_aes.c:314-321. The sendmsg() call just above the read has the same form of check. The read:
ret = (int)read(aes->rdFd, out, sz);
if (ret < 0) {
return WC_AFALG_SOCK_E;
}
Data flow:
- The function points an iovec at the input ciphertext and saves the last input block as the IV for the next call (
wolfcrypt/src/port/af_alg/afalg_aes.c:305-312). sendmsg()submits the request. A return smaller thanszis not detected.read()asks forszbytes of plaintext. A return of zero, or of fewer thanszbytes, is not detected.- The function returns 0 (
wolfcrypt/src/port/af_alg/afalg_aes.c:325).
After a zero read, out is untouched. After a short read, its tail is untouched. Nothing later in the port re-checks the data. 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). Its comments state that a short transfer leaves part of the output untouched and that read() can return less than requested.
The next-call IV comes from the input, so a short read does not corrupt the chaining state in the decrypt direction. The encrypt direction differs; see BYTERAY-2026-0490.
Reachability and Preconditions
- The library is built with
WOLFSSL_AFALG, AES-CBC and AES decryption. - The caller decrypts through
wc_AesCbcDecrypt(): TLS CBC record decryption or application code. - The kernel
cbc(aes)transform returns zero or fewer bytes than requested. This is local kernel-side state, for example a crypto driver fault or a provider removed during a session. A remote peer cannot set it, and no authentication state is involved.
Impact
Wrong plaintext is accepted as a successful decryption. The consequence is data corruption and possible confusion in the protocol layer that parses it. Nothing is disclosed directly. The failure has not been shown against a real kernel.
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 until sz bytes have arrived, and return WC_AFALG_SOCK_E on a zero or short result. Clearing the output on the error path keeps callers from using stale bytes. 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.