netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/mlx4: Check retval of mlx4_bitmap_init
@ 2022-11-15  9:53 Peter Kosyh
  2022-11-15 13:03 ` Tariq Toukan
  2022-11-16  4:32 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Kosyh @ 2022-11-15  9:53 UTC (permalink / raw)
  To: Tariq Toukan
  Cc: Peter Kosyh, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, lvc-project

If mlx4_bitmap_init fails, mlx4_bitmap_alloc_range will dereference
the NULL pointer (bitmap->table).

Make sure, that mlx4_bitmap_alloc_range called in no error case.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Peter Kosyh <pkosyh@yandex.ru>
---
 drivers/net/ethernet/mellanox/mlx4/qp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/qp.c b/drivers/net/ethernet/mellanox/mlx4/qp.c
index b149e601f673..48cfaa7eaf50 100644
--- a/drivers/net/ethernet/mellanox/mlx4/qp.c
+++ b/drivers/net/ethernet/mellanox/mlx4/qp.c
@@ -697,7 +697,8 @@ static int mlx4_create_zones(struct mlx4_dev *dev,
 			err = mlx4_bitmap_init(*bitmap + k, 1,
 					       MLX4_QP_TABLE_RAW_ETH_SIZE - 1, 0,
 					       0);
-			mlx4_bitmap_alloc_range(*bitmap + k, 1, 1, 0);
+			if (!err)
+				mlx4_bitmap_alloc_range(*bitmap + k, 1, 1, 0);
 		}
 
 		if (err)
-- 
2.38.1


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

* Re: [PATCH] net/mlx4: Check retval of mlx4_bitmap_init
  2022-11-15  9:53 [PATCH] net/mlx4: Check retval of mlx4_bitmap_init Peter Kosyh
@ 2022-11-15 13:03 ` Tariq Toukan
  2022-11-16  4:32 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2022-11-15 13:03 UTC (permalink / raw)
  To: Peter Kosyh, Tariq Toukan
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, lvc-project



On 11/15/2022 11:53 AM, Peter Kosyh wrote:
> If mlx4_bitmap_init fails, mlx4_bitmap_alloc_range will dereference
> the NULL pointer (bitmap->table).
> 
> Make sure, that mlx4_bitmap_alloc_range called in no error case.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Peter Kosyh <pkosyh@yandex.ru>
> ---
>   drivers/net/ethernet/mellanox/mlx4/qp.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx4/qp.c b/drivers/net/ethernet/mellanox/mlx4/qp.c
> index b149e601f673..48cfaa7eaf50 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/qp.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/qp.c
> @@ -697,7 +697,8 @@ static int mlx4_create_zones(struct mlx4_dev *dev,
>   			err = mlx4_bitmap_init(*bitmap + k, 1,
>   					       MLX4_QP_TABLE_RAW_ETH_SIZE - 1, 0,
>   					       0);
> -			mlx4_bitmap_alloc_range(*bitmap + k, 1, 1, 0);
> +			if (!err)
> +				mlx4_bitmap_alloc_range(*bitmap + k, 1, 1, 0);
>   		}
>   
>   		if (err)

Reviewed-by: Tariq Toukan <tariqt@nvidia.com>

Thanks for your patch.

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

* Re: [PATCH] net/mlx4: Check retval of mlx4_bitmap_init
  2022-11-15  9:53 [PATCH] net/mlx4: Check retval of mlx4_bitmap_init Peter Kosyh
  2022-11-15 13:03 ` Tariq Toukan
@ 2022-11-16  4:32 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2022-11-16  4:32 UTC (permalink / raw)
  To: Peter Kosyh
  Cc: Tariq Toukan, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	lvc-project

On Tue, 15 Nov 2022 12:53:56 +0300 Peter Kosyh wrote:
> If mlx4_bitmap_init fails, mlx4_bitmap_alloc_range will dereference
> the NULL pointer (bitmap->table).
> 
> Make sure, that mlx4_bitmap_alloc_range called in no error case.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Peter Kosyh <pkosyh@yandex.ru>

Please repost with an appropriate Fixes: tag and [PATCH net] in the
subject. Please keep Tariq's review tag.

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

end of thread, other threads:[~2022-11-16  4:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-15  9:53 [PATCH] net/mlx4: Check retval of mlx4_bitmap_init Peter Kosyh
2022-11-15 13:03 ` Tariq Toukan
2022-11-16  4:32 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).