The Linux Kernel Mailing List
 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,
	gaurav.jain@nxp.com, meenakshi.aggarwal@nxp.com,
	tudor-dan.ambarus@nxp.com, linux-kernel@vger.kernel.org
Subject: [PATCH] crypto: caam - stop RSA zero scanning at the byte limit
Date: Thu, 19 Nov 2026 14:20:07 -0500	[thread overview]
Message-ID: <20261119192007.786827-1-jeffbarnes@linux.microsoft.com> (raw)

When the requested zero prefix ends at a scatterlist-entry boundary,
caam_rsa_count_leading_zeros() calls sg_miter_next() after consuming
all requested bytes. The iterator releases the current mapping and
can return false because its bounded scatterlist is exhausted.

The scanner then assigns the previous mapping's zero count to
miter.consumed, although miter.length has been cleared. The final
sg_miter_stop() consequently warns that consumed exceeds length.

Stop scanning once the requested byte count has been reached, before
advancing the iterator.

GitHub Copilot assisted with diagnosing the iterator boundary issue,
developing the fix and regression tests, and drafting this message.

Fixes: e30685204711 ("crypto: caam - fix unchecked return value error")
Cc: stable@vger.kernel.org

Signed-off-by: Jeff Barnes <jeffbarnes@linux.microsoft.com>
---
 drivers/crypto/caam/caampkc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index 955a5dd450406..e730697678c30 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -302,7 +302,7 @@ static int caam_rsa_count_leading_zeros(struct scatterlist *sgl,
 			buff++;
 		}
 
-		if (len && *buff)
+		if (lzeros == nbytes || (len && *buff))
 			break;
 
 		if (!sg_miter_next(&miter))
-- 
2.43.0


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

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261119192007.786827-1-jeffbarnes@linux.microsoft.com \
    --to=jeffbarnes@linux.microsoft.com \
    --cc=changwei.zou@canonical.com \
    --cc=davem@davemloft.net \
    --cc=gaurav.jain@nxp.com \
    --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