[v1] common/cnxk: fix integer overflow

Message ID 20240718063437.557134-1-adwivedi@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series [v1] common/cnxk: fix integer overflow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Ankur Dwivedi July 18, 2024, 6:34 a.m. UTC
The expression flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US is
evaluated using 32 bit arithmetic. An integer overflow may occur when
the value is too large to fit in 32 bits. This patch resolves this by
casting flow_age->aging_poll_freq to 64 bit.

Coverity issue: 428156
Fixes: a4878294318e ("common/cnxk: fix flow aging on application exit")
Cc: stable@dpdk.org

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
---
 drivers/common/cnxk/roc_npc_aging.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jerin Jacob July 22, 2024, 5:39 p.m. UTC | #1
On Thu, Jul 18, 2024 at 12:13 PM Ankur Dwivedi <adwivedi@marvell.com> wrote:
>
> The expression flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US is
> evaluated using 32 bit arithmetic. An integer overflow may occur when
> the value is too large to fit in 32 bits. This patch resolves this by
> casting flow_age->aging_poll_freq to 64 bit.
>
> Coverity issue: 428156
> Fixes: a4878294318e ("common/cnxk: fix flow aging on application exit")
> Cc: stable@dpdk.org
>
> Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>

Applied to dpdk-next-net-mrvl/for-main. Thanks


> ---
>  drivers/common/cnxk/roc_npc_aging.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/common/cnxk/roc_npc_aging.c b/drivers/common/cnxk/roc_npc_aging.c
> index 1e85033e2a..258c15e341 100644
> --- a/drivers/common/cnxk/roc_npc_aging.c
> +++ b/drivers/common/cnxk/roc_npc_aging.c
> @@ -145,7 +145,7 @@ npc_age_wait_until(struct roc_npc_flow_age *flow_age)
>                 plt_delay_us(sleep);
>                 timeout += sleep;
>         } while (!flow_age->aged_flows_get_thread_exit &&
> -                (timeout < (flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US)));
> +                (timeout < ((uint64_t)flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US)));
>  }
>
>  uint32_t
> --
> 2.25.1
>
  

Patch

diff --git a/drivers/common/cnxk/roc_npc_aging.c b/drivers/common/cnxk/roc_npc_aging.c
index 1e85033e2a..258c15e341 100644
--- a/drivers/common/cnxk/roc_npc_aging.c
+++ b/drivers/common/cnxk/roc_npc_aging.c
@@ -145,7 +145,7 @@  npc_age_wait_until(struct roc_npc_flow_age *flow_age)
 		plt_delay_us(sleep);
 		timeout += sleep;
 	} while (!flow_age->aged_flows_get_thread_exit &&
-		 (timeout < (flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US)));
+		 (timeout < ((uint64_t)flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US)));
 }
 
 uint32_t