Skip to contentSkip to conversation

bnx2x: Fix potential infinite loop

PATCH In review Colin King 3 participants 3 messages Apr 7, 2021 – Apr 8, 2021

Subsystems (4)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 bnx2x: Fix potential infinite loop

From: Colin Ian King <[email protected]>

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")
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +2 -1
index 1a6ec1a12d53..edfbeb710ad4 100644
@@ -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) {
Signature · 1 line
2.30.2
maintainer
#1 lore raw

From: Colin King <[email protected]>
Date: Wed, 7 Apr 2021 15:28:02 +0100

Quoted 11 lines

From: Colin Ian King <[email protected]>

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")

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

Thank you.

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Colin King
Quoted 46 lines

-----Original Message-----
From: Colin King <[email protected]>
Sent: Wednesday, April 7, 2021 7:58 PM
To: Ariel Elior <[email protected]>; Sudarsana Reddy Kalluru <[email protected]>; GR-everest-linux-l2 <GR-everest-linux- [email protected]>; David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Eilon Greenstein <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: [EXT] [PATCH] bnx2x: Fix potential infinite loop

External Email

----------------------------------------------------------------------
From: Colin Ian King <[email protected]>

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-

Quoted 1 line

num_queues.

Addresses-Coverity: ("Infinite loop")

Fixes ad5afc89365e ("bnx2x: Separate VF and PF logic")
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +2 -2
index 1a6ec1a12d53..edfbeb710ad4 100644
@@ -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) {
--
Quoted 1 line

2.30.2

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