[PATCH] crypto: caam - stop RSA zero scanning at the byte limit
From: Jeff Barnes
Date: Thu Nov 19 2026 - 14:20:40 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Jeff Barnes <jeffbarnes@xxxxxxxxxxxxxxxxxxx>
---
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