Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] bnx2x: Fix potential infinite loop
@ 2021-04-07 14:28 Colin King
  2021-04-07 22:13 ` David Miller
  2021-04-08  1:44 ` [EXT] " Sudarsana Reddy Kalluru
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2021-04-07 14:28 UTC (permalink / raw)
  To: Ariel Elior, Sudarsana Kalluru, GR-everest-linux-l2,
	David S . Miller, Jakub Kicinski, Eilon Greenstein, netdev
  Cc: kernel-janitors, linux-kernel

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bnx2x: Fix potential infinite loop
  2021-04-07 14:28 [PATCH] bnx2x: Fix potential infinite loop Colin King
@ 2021-04-07 22:13 ` David Miller
  2021-04-08  1:44 ` [EXT] " Sudarsana Reddy Kalluru
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2021-04-07 22:13 UTC (permalink / raw)
  To: colin.king
  Cc: aelior, skalluru, GR-everest-linux-l2, kuba, eilong, netdev,
	kernel-janitors, linux-kernel

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [EXT] [PATCH] bnx2x: Fix potential infinite loop
  2021-04-07 14:28 [PATCH] bnx2x: Fix potential infinite loop Colin King
  2021-04-07 22:13 ` David Miller
@ 2021-04-08  1:44 ` Sudarsana Reddy Kalluru
  1 sibling, 0 replies; 3+ messages in thread
From: Sudarsana Reddy Kalluru @ 2021-04-08  1:44 UTC (permalink / raw)
  To: Colin King, Ariel Elior, GR-everest-linux-l2, David S . Miller,
	Jakub Kicinski, Eilon Greenstein, netdev
  Cc: kernel-janitors, linux-kernel


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 14:28 [PATCH] bnx2x: Fix potential infinite loop Colin King
2021-04-07 22:13 ` David Miller
2021-04-08  1:44 ` [EXT] " Sudarsana Reddy Kalluru

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git