Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Jeff Barnes <jeffbarnes@linux.microsoft.com>
To: linux-crypto@vger.kernel.org
Cc: herbert@gondor.apana.org.au, davem@davemloft.net,
	horia.geanta@nxp.com, pankaj.gupta@nxp.com,
	sahil.malhotra@oss.nxp.com, changwei.zou@canonical.com,
	meenakshi.aggarwal@nxp.com, tudor-dan.ambarus@nxp.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] crypto: caam - validate RSA scatterlist extents before mapping
Date: Thu, 19 Nov 2026 14:59:47 -0500	[thread overview]
Message-ID: <20261119195948.816661-2-jeffbarnes@linux.microsoft.com> (raw)
In-Reply-To: <20261119195948.816661-1-jeffbarnes@linux.microsoft.com>

rsa_edesc_alloc() passes the result of sg_nents_for_len() directly to
dma_map_sg(). An undersized source or destination scatterlist therefore
supplies a negative entry count to the DMA API. The destination alignment
walk also consumes this unchecked count.

Check both extents before walking the destination, allocating a bounce
buffer, or acquiring any DMA mappings. Propagate negative errors and
reject an empty extent with -EINVAL instead of attempting a zero-entry
mapping.

Keep this validation separate from the in-place DMA ownership fix so
that it can be backported independently.

Fixes: 8c419778ab57 ("crypto: caam - add support for RSA algorithm")
Cc: stable@vger.kernel.org
Signed-off-by: Jeff Barnes <jeffbarnes@linux.microsoft.com>
---
 drivers/crypto/caam/caampkc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 4f381b5010ab0..d81ef97861c0c 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -364,7 +364,12 @@ static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
 
 	src_nents = sg_nents_for_len(req_ctx->fixup_src,
 				     req_ctx->fixup_src_len);
+	if (unlikely(src_nents <= 0))
+		return ERR_PTR(src_nents < 0 ? src_nents : -EINVAL);
+
 	dst_nents = sg_nents_for_len(req->dst, req->dst_len);
+	if (unlikely(dst_nents <= 0))
+		return ERR_PTR(dst_nents < 0 ? dst_nents : -EINVAL);
 
 	req_ctx->bounce_buf = NULL;
 	req_ctx->fixup_dst = req->dst;
-- 
2.43.0


  reply	other threads:[~2026-11-19 20:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:59 [PATCH v2 0/2] crypto: caam - fix in-place RSA DMA mapping Jeff Barnes
2026-11-19 19:59 ` Jeff Barnes [this message]
2026-11-19 19:59 ` [PATCH v2 2/2] crypto: caam - fix in-place RSA payload " Jeff Barnes

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=20261119195948.816661-2-jeffbarnes@linux.microsoft.com \
    --to=jeffbarnes@linux.microsoft.com \
    --cc=changwei.zou@canonical.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=meenakshi.aggarwal@nxp.com \
    --cc=pankaj.gupta@nxp.com \
    --cc=sahil.malhotra@oss.nxp.com \
    --cc=tudor-dan.ambarus@nxp.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