wolfSSL — Short AF_ALG Read Reported as Full-Length RSA Output in Xilinx RSA Offload
In the Xilinx AF_ALG RSA offload path, wc_RsaFunctionSync accepts any positive return from read() as a complete result. On a short read it copies only the bytes received but reports the full key length as valid output, so the caller treats a partly stale buffer as a genuine RSA result.
- Advisory
- BYTERAY-2026-0494
- 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_XILINX_RSA (Xilinx ZynqMP RSA offload through AF_ALG)
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
Builds with WOLFSSL_AFALG_XILINX_RSA hand RSA operations to Xilinx ZynqMP hardware through the Linux kernel's AF_ALG socket interface. wc_RsaFunctionSync() sends the input on the socket and reads the result back with one read() call.
The code treats a return of -1 or 0 from that read() as an error. Any positive return is treated as a complete result. If the kernel or the hardware provider delivers fewer bytes than requested, only those bytes are copied to the caller, and the function still sets the output length to the full key length and returns success.
The caller then holds a buffer whose tail contains whatever was there before, reported as a valid RSA result. The trigger is a short transfer from the local kernel or hardware provider, not input from a remote party. Default builds do not compile this code.
Affected Products and Versions
- Component:
wolfcrypt/src/rsa.c,wc_RsaFunctionSync(), the branch selected byWOLFSSL_AFALG_XILINX_RSA(wolfcrypt/src/rsa.c:2660). - Required build:
WOLFSSL_AFALG_XILINX_RSA. The option is documented as off by default (wolfcrypt/src/rsa.c:116). - 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 result of the hardware operation is read and returned at wolfcrypt/src/rsa.c:2805-2809:
if ((ret = read(key->rdFd, outBuf, inLen)) <= 0) {
ERROR_OUT(WC_AFALG_SOCK_E);
}
XMEMCPY(out, outBuf, ret);
*outLen = keyLen;
The guard covers the hard failures only. A return where 0 < ret < inLen passes it. The copy uses ret, the number of bytes actually received. The length reported to the caller is keyLen, regardless of ret. There is no overflow. The function requires inLen == keyLen (wolfcrypt/src/rsa.c:2705-2708) and keyLen <= *outLen (wolfcrypt/src/rsa.c:2696) earlier. The unread part of the local outBuf is not copied out. The defect is the mismatch between the bytes delivered and the length reported.
Data flow:
wc_RsaFunction()dispatches towc_RsaFunctionSync(), which sets up the AF_ALG socket and installs the RSA key withsetsockopt(ALG_SET_KEY)(wolfcrypt/src/rsa.c:2770-2779).- The input is copied to
inBufand sent withsendmsg(). Only a return of zero or less is rejected (wolfcrypt/src/rsa.c:2796-2803). - The result is read at
wolfcrypt/src/rsa.c:2805. A short read passes the guard. outreceivesretbytes and*outLenis set tokeyLen(wolfcrypt/src/rsa.c:2808-2809).- The caller consumes
keyLenbytes as a signature, a decryption result or a ciphertext.
The AF_ALG AES code in the same tree states that read() on these sockets can return less than was asked for, and loops until the expected output has arrived (wolfcrypt/src/port/af_alg/afalg_aes.c:378-379). The RSA path has no such loop. The sendmsg() request at wolfcrypt/src/rsa.c:2801 has the same partial check.
Reachability and Preconditions
- Build with
WOLFSSL_AFALG_XILINX_RSA, running on Xilinx ZynqMP hardware with RSA offload. - An RSA operation (encrypt, decrypt, sign or verify) goes through
wc_RsaFunction(). - The kernel or the hardware provider returns a partial transfer on the result socket, for example after a device fault or a driver state problem.
- The return value of
read()comes from a socket the process itself created and keyed. No remote input influences it, and no trust boundary is crossed. A short read was not demonstrated on this driver.
Impact
An RSA output that is partly stale is reported as a success. A caller can build a verification or key-exchange decision on a corrupted signature, decryption result or ciphertext. This is an integrity failure with possible availability consequences. No key material is disclosed. The practical impact is bounded by the non-default build and by the need for the local kernel or hardware to misbehave.
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 verify that the transfer completed before reporting success. The RSA output length is exactly keyLen, so the function can reject any ret != inLen, or loop on read() (handling EINTR) until inLen bytes have arrived, and only then set *outLen. The same completeness check belongs on the sendmsg() request, so that a truncated command is not taken for a submitted operation. Builds without WOLFSSL_AFALG_XILINX_RSA 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.