[v2] vhost/crypto: fix out of bound access

Message ID 20220708135914.137368-1-roy.fan.zhang@intel.com (mailing list archive)
State Rejected, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] vhost/crypto: fix out of bound access |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Fan Zhang July 8, 2022, 1:59 p.m. UTC
  Coverity issue: 379211

Fixes: 4414bb67010d ("vhost/crypto: fix build with GCC 12")
Cc: david.marchand@redhat.com

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
---
v2: 
  fix format-warning

 lib/vhost/vhost_crypto.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
  

Patch

diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
index 54946f46d9..bf899d2a50 100644
--- a/lib/vhost/vhost_crypto.c
+++ b/lib/vhost/vhost_crypto.c
@@ -574,12 +574,11 @@  copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req,
 
 	remain = RTE_MIN(desc->len, size);
 	addr = desc->addr;
-	do {
-		uint64_t len;
-		void *src;
 
-		len = remain;
-		src = IOVA_TO_VVA(void *, vc_req, addr, &len, VHOST_ACCESS_RO);
+	while (remain) {
+		uint64_t len = remain;
+		void *src = IOVA_TO_VVA(void *, vc_req, addr, &len, VHOST_ACCESS_RO);
+
 		if (unlikely(src == NULL || len == 0))
 			return 0;
 
@@ -588,7 +587,7 @@  copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req,
 		/* cast is needed for 32-bit architecture */
 		dst = RTE_PTR_ADD(dst, (size_t)len);
 		addr += len;
-	} while (unlikely(remain != 0));
+	}
 
 	return RTE_MIN(desc->len, size);
 }