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>,
Praneeth Bajjuri <praneeth@ti.com>,
Vishal Mahaveer <vishalm@ti.com>, <linux-crypto@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v7 11/15] crypto: ti - Terminate DMA on all error paths in AEAD to clear descriptors
Date: Wed, 30 Sep 2026 18:28:55 +0530 [thread overview]
Message-ID: <20260930125859.1749849-12-t-pratham@ti.com> (raw)
In-Reply-To: <20260930125859.1749849-1-t-pratham@ti.com>
dmaengine_prep_slave_sg() allocates a DMA descriptor which is freed on
either successful dmaengine_submit() or on dmaengine_terminate_sync().
The error paths after descriptor allocation was not clearing them,
leaving the descriptors orphaned and leaking memory in case of failure.
Add terminate calls in dthe_aead_run() to appropriately clean the DMA
descriptors.
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 | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/ti/dthev2-aes.c b/drivers/crypto/ti/dthev2-aes.c
index ccee60800a664..ea6e3b246ed1b 100644
--- a/drivers/crypto/ti/dthev2-aes.c
+++ b/drivers/crypto/ti/dthev2-aes.c
@@ -914,6 +914,7 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
struct device *tx_dev, *rx_dev;
struct dma_async_tx_descriptor *desc_in, *desc_out, *desc_aad_out;
+ bool cleanup_tx_chan = false;
int ret;
int err;
@@ -1014,13 +1015,15 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
src_nents = sg_nents_for_len(src, cryptlen);
if (src_nents < 0) {
ret = src_nents;
- goto aead_dma_prep_aad_err;
+ cleanup_tx_chan = (assoclen != 0);
+ goto aead_dma_map_src_err;
}
src_mapped_nents = dma_map_sg(tx_dev, src, src_nents, src_dir);
if (src_mapped_nents == 0) {
dev_err(dev_data->dev, "Failed to map ciphertext src for TX\n");
ret = -EINVAL;
- goto aead_dma_prep_aad_err;
+ cleanup_tx_chan = (assoclen != 0);
+ goto aead_dma_map_src_err;
}
/* Prepare DMA descriptors for ciphertext TX */
@@ -1030,6 +1033,7 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
if (!desc_out) {
dev_err(dev_data->dev, "Ciphertext TX prep_slave_sg() failed\n");
ret = -EINVAL;
+ cleanup_tx_chan = (assoclen != 0);
goto aead_dma_prep_src_err;
}
@@ -1038,12 +1042,14 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
dst_nents = sg_nents_for_len(dst, cryptlen);
if (dst_nents < 0) {
ret = dst_nents;
+ cleanup_tx_chan = true;
goto aead_dma_prep_src_err;
}
dst_mapped_nents = dma_map_sg(rx_dev, dst, dst_nents, dst_dir);
if (dst_mapped_nents == 0) {
dev_err(dev_data->dev, "Failed to map ciphertext dst for RX\n");
ret = -EINVAL;
+ cleanup_tx_chan = true;
goto aead_dma_prep_src_err;
}
} else {
@@ -1058,6 +1064,7 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
if (!desc_in) {
dev_err(dev_data->dev, "Ciphertext RX prep_slave_sg() failed\n");
ret = -EINVAL;
+ cleanup_tx_chan = true;
goto aead_dma_prep_dst_err;
}
@@ -1147,6 +1154,10 @@ static int dthe_aead_run(struct crypto_engine *engine, void *areq)
aead_dma_prep_src_err:
if (cryptlen != 0)
dma_unmap_sg(tx_dev, src, src_nents, src_dir);
+aead_dma_map_src_err:
+ /* Free any descriptor prepared on dma_aes_tx but never submitted */
+ if (cleanup_tx_chan)
+ dmaengine_terminate_sync(dev_data->dma_aes_tx);
aead_dma_prep_aad_err:
if (assoclen != 0)
dma_unmap_sg(tx_dev, aad_sg, aad_nents, aad_dir);
--
2.34.1
next prev parent reply other threads:[~2026-09-30 12:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 12:58 [PATCH v7 00/15] Fix several issues in DTHEv2 driver T Pratham
2026-09-30 12:58 ` [PATCH v7 01/15] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() T Pratham
2026-09-30 12:58 ` [PATCH v7 02/15] crypto: ti - Fix spinlock inconsistency in DTHEv2 T Pratham
2026-09-30 12:58 ` [PATCH v7 03/15] crypto: ti - Fix potential memory corruption on highmem pages T Pratham
2026-09-30 12:58 ` [PATCH v7 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal T Pratham
2026-09-30 12:58 ` [PATCH v7 05/15] crypto: ti - Trim scatterlists to correct length in AES T Pratham
2026-09-30 12:58 ` [PATCH v7 06/15] crypto: ti - Align buffers to cacheline for DMA T Pratham
2026-09-30 12:58 ` [PATCH v7 07/15] crypto: ti - Separate padding buffer for src and dst T Pratham
2026-09-30 12:58 ` [PATCH v7 08/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AES T Pratham
2026-09-30 12:58 ` [PATCH v7 09/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AEAD T Pratham
2026-09-30 12:58 ` [PATCH v7 10/15] crypto: ti - Terminate DMA on all error paths in AES to clear descriptors T Pratham
2026-09-30 12:58 ` T Pratham [this message]
2026-09-30 12:58 ` [PATCH v7 12/15] crypto: ti - Do AEAD software fallback on only ENOMEM T Pratham
2026-09-30 12:58 ` [PATCH v7 13/15] crypto: ti - Correct AEAD tag operations against dma cache invalidation T Pratham
2026-09-30 12:58 ` [PATCH v7 14/15] crypto: ti - Change lengths in AES to u64 to avoid potential overflows T Pratham
2026-09-30 12:58 ` [PATCH v7 15/15] crypto: ti - Change lengths in AEAD " T Pratham
2026-10-01 12:56 ` [PATCH v7 00/15] Fix several issues in DTHEv2 driver T Pratham
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=20260930125859.1749849-12-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
all inboxes | Powered by JetHome®