← ALL ADVISORIES

LOW BYTERAY-2026-0492Disclosed

wolfSSL — Unchecked Short Read in AF_ALG AES-GCM Encryption Returns Stale Ciphertext and Tag

In the Linux AF_ALG port, wc_AesGcmEncrypt fetches the ciphertext and tag from the kernel crypto socket with one read() or readv() and treats only a negative return as an error. After a zero or short transfer it returns success with stale bytes in the output and tag buffers.

Advisory
BYTERAY-2026-0492
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_AesGcmEncrypt() submits the plaintext with sendmsg() and fetches the ciphertext and tag 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 returns 0. In the Xilinx branch it first copies the tag out of the output buffer at out + sz, whatever that region holds.

The caller then treats the output and tag as a finished encryption. In TLS they go on the wire and the peer fails authentication. If the output buffer previously held plaintext, that data is what gets sent. The trigger is a kernel-side condition that a remote peer does not control, 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_AesGcmEncrypt(), both branches.
  • Required build: HAVE_AESGCM with WOLFSSL_AFALG (generic branch, the #else at wolfcrypt/src/port/af_alg/afalg_aes.c:803) or WOLFSSL_AFALG_XILINX_AES (Xilinx branch, which opens at wolfcrypt/src/port/af_alg/afalg_aes.c:745). --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 Xilinx branch reads the result at wolfcrypt/src/port/af_alg/afalg_aes.c:783-787:

        ret = read(aes->rdFd, out, sz + WC_AES_BLOCK_SIZE);
        if (ret < 0) {
            return WC_AFALG_SOCK_E;
        }
        XMEMCPY(authTag, out + sz, authTagSz);

Data flow in that branch:

  1. sendmsg() submits the plaintext (wolfcrypt/src/port/af_alg/afalg_aes.c:775). Only a negative return is rejected (wolfcrypt/src/port/af_alg/afalg_aes.c:779-781).
  2. read() asks for sz + WC_AES_BLOCK_SIZE bytes into out. A return of zero, or a short return, passes.
  3. The tag is copied from out + sz. There is no loop and no length check before the copy.
  4. The function returns 0.

The generic branch has the same gap. It submits with sendmsg() (wolfcrypt/src/port/af_alg/afalg_aes.c:824), collects the ciphertext into out and the tag into authTag with one readv() (wolfcrypt/src/port/af_alg/afalg_aes.c:849), and rejects only ret < 0 (wolfcrypt/src/port/af_alg/afalg_aes.c:851-853). wc_Afalg_AesDirect() in the same file shows the intended contract. It rejects a short sendmsg() and reads in a loop that fails on ret <= 0 (wolfcrypt/src/port/af_alg/afalg_aes.c:373-385).

Reachability and Preconditions

  • The library is built with AES-GCM and one of the two AF_ALG configurations above.
  • The caller encrypts through wc_AesGcmEncrypt(): TLS 1.2 or TLS 1.3 AES-GCM record encryption, or application code.
  • The kernel gcm(aes) provider completes a zero or short transfer. This is local kernel-side state, for example a provider removed or replaced during a session. A remote peer cannot set it, and it has not been demonstrated.
  • No authentication state is involved.

Impact

Stale ciphertext and a stale tag are reported as a successful encryption. The receiving peer fails authentication, so the record and usually the connection are lost. A confidentiality risk exists only if the caller reuses an output buffer that earlier held plaintext, in which case those bytes are transmitted in place of ciphertext.

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 both result-fetch sites: read until all expected bytes have arrived, fail on a zero return or a short result, and copy the tag only after the full transfer. 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.

References