Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: caam - stop RSA zero scanning at the byte limit
@ 2026-11-19 19:20 Jeff Barnes
  0 siblings, 0 replies; only message in thread
From: Jeff Barnes @ 2026-11-19 19:20 UTC (permalink / raw)
  To: linux-crypto
  Cc: herbert, davem, horia.geanta, pankaj.gupta, sahil.malhotra,
	changwei.zou, gaurav.jain, meenakshi.aggarwal, tudor-dan.ambarus,
	linux-kernel

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 19:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:20 [PATCH] crypto: caam - stop RSA zero scanning at the byte limit Jeff Barnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox