wolfSSL — Unchecked Short Read in AF_ALG AES-GCM Decryption Returns Stale Output as Authenticated Plaintext
In the Linux AF_ALG port, wc_AesGcmDecrypt fetches the kernel's result with one read() or readv() and treats only a negative return as an error. After a zero or short transfer the function returns success, and the caller receives stale buffer contents as authenticated plaintext.
- Advisory
- BYTERAY-2026-0491
- 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 HAVE_AESGCM and WOLFSSL_AFALG (--enable-afalg) or WOLFSSL_AFALG_XILINX_AES
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The AF_ALG port sends AES-GCM operations to the Linux kernel crypto API over a socket. wc_AesGcmDecrypt() submits the ciphertext with sendmsg() and fetches the result with a single read() in the Xilinx branch, or a single readv() in the generic branch.
Only a negative return is rejected. If the kernel transfers zero bytes, or fewer than requested, the function carries on and returns 0. The output buffer then holds whatever it held before the call.
In the Xilinx branch the software tag check does not catch this. It hashes the caller's input ciphertext and compares the result with the caller's tag, and uses nothing that came back from the socket. A valid record therefore passes the check while its plaintext was never written. 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_AesGcmDecrypt(), both branches. - Required build:
HAVE_AESGCMwithWOLFSSL_AFALG(generic branch) orWOLFSSL_AFALG_XILINX_AES(Xilinx branch, which opens atwolfcrypt/src/port/af_alg/afalg_aes.c:953).--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 Xilinx branch reads the result at wolfcrypt/src/port/af_alg/afalg_aes.c:1003-1006:
ret = read(aes->rdFd, out, sz + WC_AES_BLOCK_SIZE);
if (ret < 0) {
return AES_GCM_AUTH_E;
}
Data flow in that branch:
sendmsg()submits the ciphertext and tag (wolfcrypt/src/port/af_alg/afalg_aes.c:995). Only a negative return is rejected (wolfcrypt/src/port/af_alg/afalg_aes.c:999-1001).read()asks forsz + WC_AES_BLOCK_SIZEbytes intoout. A return of zero, or a short return, passes.- When additional data is present, the tag is recomputed with
GHASHover the inputin, combined with the encrypted counter block, and compared with the caller'sauthTag(wolfcrypt/src/port/af_alg/afalg_aes.c:1009-1018). No byte ofouttakes part. - The function returns 0.
The generic branch has the same gap. It collects the result with readv() (wolfcrypt/src/port/af_alg/afalg_aes.c:1059) and rejects only ret < 0 (wolfcrypt/src/port/af_alg/afalg_aes.c:1062-1064). wc_Afalg_AesDirect() in the same file shows the intended contract: a read loop that fails on ret <= 0 (wolfcrypt/src/port/af_alg/afalg_aes.c:378-385).
This is not a way to forge a tag. The tag comparison is genuine. The defect is that a passing check can be paired with an output buffer the kernel did not fill.
Reachability and Preconditions
- The library is built with AES-GCM and one of the two AF_ALG configurations above.
- The caller decrypts through
wc_AesGcmDecrypt(): TLS AES-GCM record decryption or application code. - The kernel
gcm(aes)provider completes a zero or short transfer. This is a local condition such as a crypto driver fault. A remote peer cannot set it. - No authentication is bypassed. The ciphertext and tag must still be valid for the call to succeed.
Impact
Stale or partial buffer contents are delivered to the caller as successfully decrypted and authenticated data. The record layer or application then parses bytes that are not the plaintext. The effect is an integrity failure of the decrypted data and misbehaviour in the consumer. No confidentiality loss 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 enforce the full read at both sites. The call should succeed only when the expected number of bytes has arrived, either by looping until the length is consumed or by failing on any zero or short result. The tag verification can stay where it is. Builds without the AF_ALG AES port 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.