mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Elkin Cruz <elkin@google.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	 llvm@lists.linux.dev, irogers@google.com,
	Elkin Cruz <elkin@google.com>,
	 stable@vger.kernel.org
Subject: [PATCH] crypto: sa2ul - fall back to software when assoclen exceeds u8 enc_offset
Date: Wed, 25 Nov 2026 22:25:03 +0000	[thread overview]
Message-ID: <20261125222503.1445426-1-elkin@google.com> (raw)

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@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---

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


                 reply	other threads:[~2026-11-25 22:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125222503.1445426-1-elkin@google.com \
    --to=elkin@google.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=irogers@google.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®