From: T Pratham <t-pratham@ti.com>
To: T Pratham <t-pratham@ti.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Sebin Francis <sebin.francis@ti.com>,
Manorit Chawdhry <m-chawdhry@ti.com>,
Vishal Mahaveer <vishalm@ti.com>,
Praneeth Bajjuri <praneeth@ti.com>,
<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v4 15/15] crypto: ti - Change lengths in AEAD to u64 to avoid potential overflows
Date: Thu, 10 Sep 2026 23:26:19 +0530 [thread overview]
Message-ID: <20260910175619.2122149-16-t-pratham@ti.com> (raw)
In-Reply-To: <20260910175619.2122149-1-t-pratham@ti.com>
Change assoclen, cryptlen, authsize from unsigned int to u64 to avoid
overflow when they are added (in TAG offset and padding length
calculation)
Fixes: 37b902c603042 ("crypto: ti - Add support for AES-GCM in DTHEv2 driver")
Signed-off-by: T Pratham <t-pratham@ti.com>
---
drivers/crypto/ti/dthev2-aes.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/drivers/crypto/ti/dthev2-aes.c b/drivers/crypto/ti/dthev2-aes.c
index 9b982ca4a7730..ca87aacc39c5d 100644
--- a/drivers/crypto/ti/dthev2-aes.c
+++ b/drivers/crypto/ti/dthev2-aes.c
@@ -756,6 +756,9 @@ static int dthe_aead_enc_get_tag(struct aead_request *req)
struct dthe_tfm_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req));
struct dthe_aes_req_ctx *rctx = aead_request_ctx(req);
u32 tag[AES_BLOCK_WORDS];
+ u64 assoclen = req->assoclen;
+ u64 cryptlen = req->cryptlen;
+ u64 authsize = ctx->authsize;
int nents;
int ret;
@@ -763,12 +766,12 @@ static int dthe_aead_enc_get_tag(struct aead_request *req)
if (ret)
return ret;
- nents = sg_nents_for_len(req->dst, req->cryptlen + req->assoclen + ctx->authsize);
+ nents = sg_nents_for_len(req->dst, cryptlen + assoclen + authsize);
if (nents < 0)
return nents;
- sg_pcopy_from_buffer(req->dst, nents, tag, ctx->authsize,
- req->assoclen + req->cryptlen);
+ sg_pcopy_from_buffer(req->dst, nents, tag, authsize,
+ assoclen + cryptlen);
return 0;
}
@@ -779,6 +782,9 @@ static int dthe_aead_dec_verify_tag(struct aead_request *req)
struct dthe_aes_req_ctx *rctx = aead_request_ctx(req);
u32 tag_out[AES_BLOCK_WORDS];
u32 tag_in[AES_BLOCK_WORDS];
+ u64 assoclen = req->assoclen;
+ u64 cryptlen = req->cryptlen;
+ u64 authsize = ctx->authsize;
int nents;
int ret;
@@ -786,14 +792,14 @@ static int dthe_aead_dec_verify_tag(struct aead_request *req)
if (ret)
return ret;
- nents = sg_nents_for_len(req->src, req->assoclen + req->cryptlen);
+ nents = sg_nents_for_len(req->src, assoclen + cryptlen);
if (nents < 0)
return nents;
- sg_pcopy_to_buffer(req->src, nents, tag_in, ctx->authsize,
- req->assoclen + req->cryptlen - ctx->authsize);
+ sg_pcopy_to_buffer(req->src, nents, tag_in, authsize,
+ assoclen + cryptlen - authsize);
- if (crypto_memneq(tag_in, tag_out, ctx->authsize))
+ if (crypto_memneq(tag_in, tag_out, authsize))
return -EBADMSG;
else
return 0;
@@ -887,10 +893,10 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
struct dthe_aes_req_ctx *rctx = aead_request_ctx(req);
struct dthe_data *dev_data = rctx->dev_data;
- unsigned int cryptlen = req->cryptlen;
- unsigned int assoclen = req->assoclen;
- unsigned int authsize = ctx->authsize;
- unsigned int unpadded_cryptlen;
+ u64 cryptlen = req->cryptlen;
+ u64 assoclen = req->assoclen;
+ u64 authsize = ctx->authsize;
+ u64 unpadded_cryptlen;
struct scatterlist *src = NULL;
struct scatterlist *dst = NULL;
struct scatterlist *aad_sg = NULL;
--
2.34.1
prev parent reply other threads:[~2026-09-10 17:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 17:56 [PATCH v4 00/15] Fix several issues in DTHEv2 driver T Pratham
2026-09-10 17:56 ` [PATCH v4 01/15] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() T Pratham
2026-09-10 17:56 ` [PATCH v4 02/15] crypto: ti - Fix spinlock inconsistency in DTHEv2 T Pratham
2026-09-10 17:56 ` [PATCH v4 03/15] crypto: ti - Fix potential memory corruption on highmem pages T Pratham
2026-09-10 17:56 ` [PATCH v4 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal T Pratham
2026-09-10 17:56 ` [PATCH v4 05/15] crypto: ti - Trim scatterlists to correct length in AES T Pratham
2026-09-10 17:56 ` [PATCH v4 06/15] crypto: ti - Align buffers to cacheline for DMA T Pratham
2026-09-10 17:56 ` [PATCH v4 07/15] crypto: ti - Separate padding buffer for src and dst T Pratham
2026-09-10 17:56 ` [PATCH v4 08/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AES T Pratham
2026-09-10 17:56 ` [PATCH v4 09/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AEAD T Pratham
2026-09-10 17:56 ` [PATCH v4 10/15] crypto: ti - Terminate DMA on all error paths in AES to clear descriptors T Pratham
2026-09-10 17:56 ` [PATCH v4 11/15] crypto: ti - Terminate DMA on all error paths in AEAD " T Pratham
2026-09-10 17:56 ` [PATCH v4 12/15] crypto: ti - Do AEAD software fallback on only ENOMEM T Pratham
2026-09-10 17:56 ` [PATCH v4 13/15] crypto: ti - Correct AEAD tag operations against dma cache invalidation T Pratham
2026-09-10 17:56 ` [PATCH v4 14/15] crypto: ti - Change lengths in AES to u64 to avoid potential overflows T Pratham
2026-09-10 17:56 ` T Pratham [this message]
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=20260910175619.2122149-16-t-pratham@ti.com \
--to=t-pratham@ti.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m-chawdhry@ti.com \
--cc=praneeth@ti.com \
--cc=sebin.francis@ti.com \
--cc=vishalm@ti.com \
/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