[PATCH v3 07/12] crypto: ti - Separate padding buffer for src and dst
From: T Pratham
Date: Thu Sep 10 2026 - 06:52:12 EST
Separate the padding buffer, which is allocated in the req ctx, for src
and dst scatterlist to avoid any DMA mapping issues when not doing
inline operations. In such cases, the current code was mapping the same
padding buffer twice which might cause issues.
Fixes: 35645ca63caa1 ("crypto: ti - Add support for AES-CTR in DTHEv2 driver")
Signed-off-by: T Pratham <t-pratham@xxxxxx>
---
drivers/crypto/ti/dthev2-aes.c | 19 ++++++++++++-------
drivers/crypto/ti/dthev2-common.h | 2 +-
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/crypto/ti/dthev2-aes.c b/drivers/crypto/ti/dthev2-aes.c
index be7ec62ab2513..aeccc235cb667 100644
--- a/drivers/crypto/ti/dthev2-aes.c
+++ b/drivers/crypto/ti/dthev2-aes.c
@@ -338,6 +338,9 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
int src_mapped_nents;
int dst_mapped_nents;
+ u8 *src_padding = rctx->padding;
+ u8 *dst_padding = rctx->padding + AES_BLOCK_SIZE;
+
bool diff_dst;
enum dma_data_direction src_dir, dst_dir;
@@ -388,8 +391,8 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
sg_init_table(src, src_nents);
sg = dthe_copy_sg(src, req->src, req->cryptlen);
if (pad_len > 0) {
- memzero_explicit(rctx->padding, AES_BLOCK_SIZE);
- sg_set_buf(sg, rctx->padding, pad_len);
+ memzero_explicit(src_padding, AES_BLOCK_SIZE);
+ sg_set_buf(sg, src_padding, pad_len);
}
if (diff_dst) {
@@ -401,8 +404,10 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
sg_init_table(dst, dst_nents);
sg = dthe_copy_sg(dst, req->dst, req->cryptlen);
- if (pad_len > 0)
- sg_set_buf(sg, rctx->padding, pad_len);
+ if (pad_len > 0) {
+ memzero_explicit(dst_padding, AES_BLOCK_SIZE);
+ sg_set_buf(sg, dst_padding, pad_len);
+ }
} else {
dst = src;
}
@@ -492,7 +497,7 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
aes_map_src_err:
if (ctx->aes_mode == DTHE_AES_CTR && req->cryptlen % AES_BLOCK_SIZE)
- memzero_explicit(rctx->padding, AES_BLOCK_SIZE);
+ memzero_explicit(rctx->padding, 2 * AES_BLOCK_SIZE);
if (diff_dst)
kfree(dst);
@@ -882,7 +887,7 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
u8 *src_assoc_padbuf = rctx->padding;
u8 *src_crypt_padbuf = rctx->padding + AES_BLOCK_SIZE;
- u8 *dst_crypt_padbuf = rctx->padding + AES_BLOCK_SIZE;
+ u8 *dst_crypt_padbuf = rctx->padding + 2 * AES_BLOCK_SIZE;
bool diff_dst;
enum dma_data_direction aad_dir, src_dir, dst_dir;
@@ -1125,7 +1130,7 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
kfree(aad_sg);
aead_prep_aad_err:
- memzero_explicit(rctx->padding, 2 * AES_BLOCK_SIZE);
+ memzero_explicit(rctx->padding, 3 * AES_BLOCK_SIZE);
if (ret)
ret = dthe_aead_do_fallback(req);
diff --git a/drivers/crypto/ti/dthev2-common.h b/drivers/crypto/ti/dthev2-common.h
index cfb50255a5dce..f78420ba871e2 100644
--- a/drivers/crypto/ti/dthev2-common.h
+++ b/drivers/crypto/ti/dthev2-common.h
@@ -115,7 +115,7 @@ struct dthe_tfm_ctx {
struct dthe_aes_req_ctx {
int enc;
__dma_from_device_group_begin();
- u8 padding[2 * AES_BLOCK_SIZE];
+ u8 padding[3 * AES_BLOCK_SIZE];
__dma_from_device_group_end();
struct completion aes_compl;
struct dthe_data *dev_data;
--
2.34.1