diff mbox series

bnx2x: Fix potential infinite loop

Message ID 20210407142802.495539-1-colin.king@canonical.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series bnx2x: Fix potential infinite loop | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Colin King April 7, 2021, 2:28 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The for_each_tx_queue loop iterates with a u8 loop counter i and
compares this with the loop upper limit of bp->num_queues that
is an int type.  There is a potential infinite loop if bp->num_queues
is larger than the u8 loop counter. Fix this by making the loop
counter the same type as bp->num_queues.

Addresses-Coverity: ("Infinite loop")
Fixes: ad5afc89365e ("bnx2x: Separate VF and PF logic")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Miller April 7, 2021, 10:13 p.m. UTC | #1
From: Colin King <colin.king@canonical.com>
Date: Wed,  7 Apr 2021 15:28:02 +0100

> From: Colin Ian King <colin.king@canonical.com>
> 
> The for_each_tx_queue loop iterates with a u8 loop counter i and
> compares this with the loop upper limit of bp->num_queues that
> is an int type.  There is a potential infinite loop if bp->num_queues
> is larger than the u8 loop counter. Fix this by making the loop
> counter the same type as bp->num_queues.
> 
> Addresses-Coverity: ("Infinite loop")
> Fixes: ad5afc89365e ("bnx2x: Separate VF and PF logic")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Please show how num_queues can take on a value larger than 255.

Thank you.
Sudarsana Reddy Kalluru April 8, 2021, 1:44 a.m. UTC | #2
> -----Original Message-----
> From: Colin King <colin.king@canonical.com>
> Sent: Wednesday, April 7, 2021 7:58 PM
> To: Ariel Elior <aelior@marvell.com>; Sudarsana Reddy Kalluru
> <skalluru@marvell.com>; GR-everest-linux-l2 <GR-everest-linux-
> l2@marvell.com>; David S . Miller <davem@davemloft.net>; Jakub Kicinski
> <kuba@kernel.org>; Eilon Greenstein <eilong@broadcom.com>;
> netdev@vger.kernel.org
> Cc: kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [EXT] [PATCH] bnx2x: Fix potential infinite loop
> 
> External Email
> 
> ----------------------------------------------------------------------
> From: Colin Ian King <colin.king@canonical.com>
> 
> The for_each_tx_queue loop iterates with a u8 loop counter i and compares
> this with the loop upper limit of bp->num_queues that is an int type.  There
> is a potential infinite loop if bp->num_queues is larger than the u8 loop
> counter. Fix this by making the loop counter the same type as bp-
> >num_queues.
> 
> Addresses-Coverity: ("Infinite loop")
> Fixes: ad5afc89365e ("bnx2x: Separate VF and PF logic")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> index 1a6ec1a12d53..edfbeb710ad4 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> @@ -2959,7 +2959,8 @@ int bnx2x_nic_load(struct bnx2x *bp, int
> load_mode)
> 
>  int bnx2x_drain_tx_queues(struct bnx2x *bp)  {
> -	u8 rc = 0, cos, i;
> +	u8 rc = 0, cos;
> +	int i;
> 
>  	/* Wait until tx fastpath tasks complete */
>  	for_each_tx_queue(bp, i) {
> --
> 2.30.2

Thanks for the change. [just for the info, theoretical max num_queues value for bnx2x device is 33]

Acked-by: Sudarsana Reddy Kalluru <skalluru@marvell.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 1a6ec1a12d53..edfbeb710ad4 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -2959,7 +2959,8 @@  int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
 
 int bnx2x_drain_tx_queues(struct bnx2x *bp)
 {
-	u8 rc = 0, cos, i;
+	u8 rc = 0, cos;
+	int i;
 
 	/* Wait until tx fastpath tasks complete */
 	for_each_tx_queue(bp, i) {