Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] crypto: xts - Replace memcpy() invocation with simple assignment
@ 2020-07-21  6:05 Ard Biesheuvel
  2020-07-31 13:29 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Ard Biesheuvel @ 2020-07-21  6:05 UTC (permalink / raw)
  To: linux-crypto; +Cc: herbert, colin.king, 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.

Addresses-Coverity: ("Overlapping buffer in memory copy")
Fixes: 8083b1bf8163 ("crypto: xts - add support for ciphertext stealing")
Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 crypto/xts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/xts.c b/crypto/xts.c
index 3c3ed02c7663..ad45b009774b 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -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);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: xts - Replace memcpy() invocation with simple assignment
  2020-07-21  6:05 [PATCH] crypto: xts - Replace memcpy() invocation with simple assignment Ard Biesheuvel
@ 2020-07-31 13:29 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2020-07-31 13:29 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-crypto, colin.king

On Tue, Jul 21, 2020 at 09:05:54AM +0300, Ard Biesheuvel wrote:
> 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")
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  crypto/xts.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21  6:05 [PATCH] crypto: xts - Replace memcpy() invocation with simple assignment Ard Biesheuvel
2020-07-31 13:29 ` Herbert Xu

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git