Skip to contentSkip to conversation

crypto: caam - stop RSA zero scanning at the byte limit

PATCH New Jeff Barnes 1 participant 1 message Nov 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: caam - stop RSA zero scanning at the byte limit

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")
---
 drivers/crypto/caam/caampkc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/caam/caampkc.c +1 -1
index 955a5dd450406..e730697678c30 100644
@@ -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))
Signature · 1 line
2.43.0