[PATCH] crypto: sa2ul - fall back to software when assoclen exceeds u8 enc_offset

From: Elkin Cruz

Date: Wed Nov 25 2026 - 17:25:48 EST


In sa_aead_run(), req->assoclen (unsigned int) is assigned to
sa_req.enc_offset, which is a u8 field corresponding to the 8-bit
SA_CMDL_SOP_BYPASS_LEN_MASK hardware command-label field. The existing
fallback check only tests auth_size against SA_MAX_DATA_SZ (65535) and
the unsafe [240, 255] packet size window, allowing requests with
req->assoclen >= 256 to silently truncate enc_offset modulo 256 and
corrupt encryption/authentication offsets in hardware.

Fall back to the software AEAD implementation whenever
req->assoclen > U8_MAX, and compute auth_size in u64 to avoid 32-bit
size_t addition wrap-around.

Fixes: d2c8ac187fc9 ("crypto: sa2ul - Add AEAD algorithm support")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
---

I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).

Thanks,
Elkin

drivers/crypto/sa2ul.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index f8216b5d3991..1d9cb5932b25 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -1771,17 +1771,18 @@ static int sa_aead_run(struct aead_request *req, u8 *iv, int enc)
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
struct sa_tfm_ctx *ctx = crypto_aead_ctx(tfm);
struct sa_req sa_req = { 0 };
- size_t auth_size, enc_size;
+ u64 auth_size;
+ size_t enc_size;

enc_size = req->cryptlen;
- auth_size = req->assoclen + req->cryptlen;
+ auth_size = (u64)req->assoclen + req->cryptlen;

if (!enc) {
enc_size -= crypto_aead_authsize(tfm);
auth_size -= crypto_aead_authsize(tfm);
}

- if (auth_size > SA_MAX_DATA_SZ ||
+ if (req->assoclen > U8_MAX || auth_size > SA_MAX_DATA_SZ ||
(auth_size >= SA_UNSAFE_DATA_SZ_MIN &&
auth_size <= SA_UNSAFE_DATA_SZ_MAX)) {
struct aead_request *subreq = aead_request_ctx(req);
--
2.56.1.839.g22a8290db9-goog