[PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs()

From: Lee Jones

Date: Mon Nov 23 2026 - 10:12:29 EST


In qce_ahash_async_req_handle(), dma_map_sg() maps req->src and returns
the number of coalesced DMA segments in ret, which is immediately
overwritten when mapping rctx->result_sg. The function then passes the
unmapped segment count rctx->src_nents to qce_dma_prep_sgs().

When an IOMMU coalesces scatterlist entries so the mapped count is
smaller than rctx->src_nents, dmaengine_prep_slave_sg() walks past the
mapped entries and reads uninitialised DMA addresses and lengths from
the tail of req->src, while dma_unmap_sg() still requires the original
rctx->src_nents count.

Save the mapped segment count from dma_map_sg() in a dedicated
src_nents variable and pass it to qce_dma_prep_sgs(), matching the
skcipher path.

Fixes: ec8f5d8f6f76 ("crypto: qce - Qualcomm crypto engine driver")
Closes: https://sashiko.dev/#/bug/linux-24490c31-257a-4148-a816-0aaf416f64a1
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/crypto/qce/sha.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index b67d749db05f..56106f415db6 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -77,7 +77,7 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
struct qce_alg_template *tmpl = to_ahash_tmpl(async_req->tfm);
struct qce_device *qce = tmpl->qce;
unsigned long flags = rctx->flags;
- int ret;
+ int ret, src_nents;

if (IS_SHA_HMAC(flags)) {
rctx->authkey = ctx->authkey;
@@ -93,8 +93,9 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
return rctx->src_nents;
}

- ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE);
- if (!ret)
+ src_nents = dma_map_sg(qce->dev, req->src, rctx->src_nents,
+ DMA_TO_DEVICE);
+ if (!src_nents)
return -EIO;

sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);
@@ -105,7 +106,7 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
goto error_unmap_src;
}

- ret = qce_dma_prep_sgs(&qce->dma, req->src, rctx->src_nents,
+ ret = qce_dma_prep_sgs(&qce->dma, req->src, src_nents,
&rctx->result_sg, 1, qce_ahash_done, async_req);
if (ret)
goto error_unmap_dst;
--
2.56.1.750.gf70dc682cf-goog