raw/ifpga: avoid potential integer overflow
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
--- drivers/raw/ifpga/afu_pmd_n3000.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/afu_pmd_n3000.c +2 -2
@@ -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
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 overflowExpression "
tx_chunks*ctx->dma_buf_size" indma_fpga_to_fpga()is evaluated using 32-bit arithmetic, which would overflow potentially. Changetx_chunksto type "uint64_t" to avoid such issue.Coverity issue: 379203
Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")Signed-off-by Wei Huang <[email protected]>--- drivers/raw/ifpga/afu_pmd_n3000.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/raw/ifpga/afu_pmd_n3000.c +2
-2@@ -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.
Thomas Monjalon
AppliedQuoted 4 lines
Quoted 4 lines
Expression "
tx_chunks*ctx->dma_buf_size" indma_fpga_to_fpga()is evaluated using 32-bit arithmetic, which would overflow potentially. Changetx_chunksto type "uint64_t" to avoid such issue.
Quoted 8 lines
Quoted 4 lines
Coverity issue: 379203
Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")Signed-off-by Wei Huang <[email protected]>It looks good for me.
Acked-by Tianfei Zhang <[email protected]>
Applied, thanks.
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 overflowExpression "
tx_chunks*ctx->dma_buf_size" indma_fpga_to_fpga()is evaluated using 32-bit arithmetic, which would overflow potentially. Changetx_chunksto type "uint64_t" to avoid such issue.Coverity issue: 379203
Fixes 7d63899a5c19 ("raw/ifpga: add N3000 AFU driver")Signed-off-by Wei Huang <[email protected]>--- drivers/raw/ifpga/afu_pmd_n3000.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/raw/ifpga/afu_pmd_n3000.c +1
-1@@ -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