Skip to contentSkip to conversation

crypto: xts - Replace memcpy() invocation with simple assignment

PATCH In review Ard Biesheuvel 2 participants 2 messages Jul 21, 2020 – Jul 31, 2020 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: xts - Replace memcpy() invocation with simple assignment

Colin reports that the memcpy() call in xts_cts_final() trigggers a "Overlapping buffer in memory copy" warning in Coverity, which is a false postive, given that tail is guaranteed to be smaller than or equal to the distance between source and destination.

However, given that any additional bytes that we copy will be ignored anyway, we can simply copy XTS_BLOCK_SIZE unconditionally, which means we can use struct assignment of the array members instead, which is likely to be more efficient as well.

Addresses-Coverity: ("Overlapping buffer in memory copy")

Fixes 8083b1bf8163 ("crypto: xts - add support for ciphertext stealing")
---
 crypto/xts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/xts.c +1 -1
index 3c3ed02c7663..ad45b009774b 100644
@@ -171,7 +171,7 @@ static int xts_cts_final(struct skcipher_request *req,
 				      offset - XTS_BLOCK_SIZE);
 
 	scatterwalk_map_and_copy(b, rctx->tail, 0, XTS_BLOCK_SIZE, 0);
-	memcpy(b + 1, b, tail);
+	b[1] = b[0];
 	scatterwalk_map_and_copy(b, req->src, offset, tail, 0);
 
 	le128_xor(b, &rctx->t, b);
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 10 lines · Ard Biesheuvel

Colin reports that the memcpy() call in xts_cts_final() trigggers a "Overlapping buffer in memory copy" warning in Coverity, which is a false postive, given that tail is guaranteed to be smaller than or equal to the distance between source and destination.

However, given that any additional bytes that we copy will be ignored anyway, we can simply copy XTS_BLOCK_SIZE unconditionally, which means we can use struct assignment of the array members instead, which is likely to be more efficient as well.

Quoted 7 lines

Addresses-Coverity: ("Overlapping buffer in memory copy")

Fixes 8083b1bf8163 ("crypto: xts - add support for ciphertext stealing")
---
 crypto/xts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

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