Skip to contentSkip to conversation

crypto: talitos - fix bug in sg_copy_end_to_buffer

PATCH Applied Lee Nipper 2 participants 2 messages Jul 14, 2010 – Jul 19, 2010 Crypto API

lore
Share & tools
lore

Lee Nipper

author
#0 lore raw

PATCH v2 1/1 crypto: talitos - fix bug in sg_copy_end_to_buffer

In function sg_copy_end_to_buffer, too much data is copied when a segment in the scatterlist has .length greater than the requested copy length.

This patch adds the limit checks to fix this bug of over copying, which affected only the ahash algorithms.

---
This is version 2 of this patch,
with changes per Kim's review: unnecessary parenthesis removed.

 drivers/crypto/talitos.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/crypto/talitos.c +5 -1
index 0f2483e..e058987 100644
@@ -1183,10 +1183,14 @@ static size_t sg_copy_end_to_buffer(struct scatterlist *sgl, unsigned int nents,
 				/* Copy part of this segment */
 				ignore = skip - offset;
 				len = miter.length - ignore;
+				if (boffset + len > buflen)
+					len = buflen - boffset;
 				memcpy(buf + boffset, miter.addr + ignore, len);
 			} else {
-				/* Copy all of this segment */
+				/* Copy all of this segment (up to buflen) */
 				len = miter.length;
+				if (boffset + len > buflen)
+					len = buflen - boffset;
 				memcpy(buf + boffset, miter.addr, len);
 			}
 			boffset += len;
Signature · 1 line
1.6.0.4
maintainer Applied
#1 lore raw
Quoted 9 lines · Lee Nipper

In function sg_copy_end_to_buffer, too much data is copied when a segment in the scatterlist has .length greater than the requested copy length.

This patch adds the limit checks to fix this bug of over copying, which affected only the ahash algorithms.

Applied to crypto-2.6. Thanks Lee!

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt