Skip to contentSkip to conversation

raw/ifpga: avoid potential integer overflow

PATCH Applied Wei Huang 4 participants 4 messages Jun 23, 2022 – Jun 26, 2022

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 raw/ifpga: avoid potential integer overflow

Expression "tx_chunks * ctx->dma_buf_size" in dma_fpga_to_fpga() is evaluated using 32-bit arithmetic, which would overflow
potentially. Change tx_chunks to type "uint64_t" to avoid such
issue.

Coverity issue: 379203

Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")
---
 drivers/raw/ifpga/afu_pmd_n3000.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/afu_pmd_n3000.c +2 -2
index 8708164..5120df5 100644
@@ -1158,7 +1158,7 @@ static int dma_fpga_to_fpga(struct dma_afu_ctx *ctx, uint64_t dst, uint64_t src,
 	uint64_t count_left = count;
 	uint64_t dma_chunks = 0;
 	uint64_t offset = 0;
-	uint32_t tx_chunks = 0;
+	uint64_t tx_chunks = 0;
 	uint64_t *tmp_buf = NULL;
 	int ret = 0;
 
@@ -1213,7 +1213,7 @@ static int dma_fpga_to_fpga(struct dma_afu_ctx *ctx, uint64_t dst, uint64_t src,
 		offset = tx_chunks * ctx->dma_buf_size;
 		count_left -= offset;
 		IFPGA_RAWDEV_PMD_DEBUG("0x%"PRIx64" --> 0x%"PRIx64
-			" (%u...0x%"PRIx64")",
+			" (%"PRIu64"...0x%"PRIx64")",
 			src, dst, tx_chunks, count_left);
 		tmp_buf = (uint64_t *)rte_malloc(NULL, ctx->dma_buf_size,
 			DMA_ALIGN_BYTES);
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 48 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, June 23, 2022 11:12 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
Subject: [PATCH] raw/ifpga: avoid potential integer overflow

Expression "tx_chunks * ctx->dma_buf_size" in dma_fpga_to_fpga() is evaluated using 32-bit arithmetic, which would overflow potentially. Change tx_chunks to type "uint64_t" to avoid such issue.

Coverity issue: 379203

Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")
---
 drivers/raw/ifpga/afu_pmd_n3000.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/afu_pmd_n3000.c +2 -2
index 8708164..5120df5 100644
@@ -1158,7 +1158,7 @@ static int dma_fpga_to_fpga(struct dma_afu_ctx
 *ctx, uint64_t dst, uint64_t src,
 	uint64_t count_left = count;
 	uint64_t dma_chunks = 0;
 	uint64_t offset = 0;
-	uint32_t tx_chunks = 0;
+	uint64_t tx_chunks = 0;
 	uint64_t *tmp_buf = NULL;
 	int ret = 0;
@@ -1213,7 +1213,7 @@ static int dma_fpga_to_fpga(struct dma_afu_ctx
 *ctx, uint64_t dst, uint64_t src,
 		offset = tx_chunks * ctx->dma_buf_size;
 		count_left -= offset;
 		IFPGA_RAWDEV_PMD_DEBUG("0x%"PRIx64" --> 0x%"PRIx64
-			" (%u...0x%"PRIx64")",
+			" (%"PRIu64"...0x%"PRIx64")",
 			src, dst, tx_chunks, count_left);
 		tmp_buf = (uint64_t *)rte_malloc(NULL, ctx->dma_buf_size,
Quoted 3 lines

DMA_ALIGN_BYTES);
--
1.8.3.1

It looks good for me.

#2 lore raw
Quoted 4 lines
Quoted 4 lines

Expression "tx_chunks * ctx->dma_buf_size" in dma_fpga_to_fpga() is evaluated using 32-bit arithmetic, which would overflow potentially. Change tx_chunks to type "uint64_t" to avoid such issue.

Quoted 8 lines
Quoted 4 lines

Coverity issue: 379203

Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")

It looks good for me.

Applied, thanks.

Acked-by on v1 1/1
#3 lore raw
In reply to Wei Huang

Hi,

Quoted 49 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, June 23, 2022 11:12
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
Subject: [PATCH] raw/ifpga: avoid potential integer overflow

Expression "tx_chunks * ctx->dma_buf_size" in dma_fpga_to_fpga() is evaluated using 32-bit arithmetic, which would overflow potentially. Change tx_chunks to type "uint64_t" to avoid such issue.

Coverity issue: 379203

Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")
---
 drivers/raw/ifpga/afu_pmd_n3000.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/afu_pmd_n3000.c +1 -1
index 8708164..5120df5 100644
@@ -1158,7 +1158,7 @@ static int dma_fpga_to_fpga(struct dma_afu_ctx
 *ctx, uint64_t dst, uint64_t src,
 	uint64_t count_left = count;
 	uint64_t dma_chunks = 0;
 	uint64_t offset = 0;
-	uint32_t tx_chunks = 0;
+	uint64_t tx_chunks = 0;
 	uint64_t *tmp_buf = NULL;
 	int ret = 0;
@@ -1213,7 +1213,7 @@ static int dma_fpga_to_fpga(struct dma_afu_ctx
 *ctx, uint64_t dst, uint64_t src,
 		offset = tx_chunks * ctx->dma_buf_size;
 		count_left -= offset;
 		IFPGA_RAWDEV_PMD_DEBUG("0x%"PRIx64" -->

0x%"PRIx64

drivers/raw/ifpga/afu_pmd_n3000.c +1 -2
-			" (%u...0x%"PRIx64")",
+			" (%"PRIu64"...0x%"PRIx64")",
 			src, dst, tx_chunks, count_left);
 		tmp_buf = (uint64_t *)rte_malloc(NULL, ctx->dma_buf_size,
 			DMA_ALIGN_BYTES);
--
Quoted 1 line

1.8.3.1