Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Bartosz Golaszewski <brgl@kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Thorsten Blum <blum@kernel.org>,
	Stanimir Varbanov <svarbanov@mm-sol.com>,
	linux-crypto@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs()
Date: Mon, 23 Nov 2026 15:09:59 +0000	[thread overview]
Message-ID: <20261123151055.2533735-9-lee@kernel.org> (raw)
In-Reply-To: <20261123151055.2533735-1-lee@kernel.org>

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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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


  reply	other threads:[~2026-11-23 15:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:09 [PATCH 00/10] crypto: Assorted bug fixes across crypto drivers Lee Jones
2026-11-23 15:09 ` Lee Jones [this message]
2026-11-23 15:10 ` [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails Lee Jones

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=20261123151055.2533735-9-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=blum@kernel.org \
    --cc=brgl@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=svarbanov@mm-sol.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