All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources()
@ 2021-11-30 16:44 Zhou Qingyang
  2021-12-01  9:27 ` Leon Romanovsky
  2021-12-02  3:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Zhou Qingyang @ 2021-11-30 16:44 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Tariq Toukan, David S. Miller, Jakub Kicinski,
	Eugenia Emantayev, netdev, linux-rdma, linux-kernel

In mlx4_en_try_alloc_resources(), mlx4_en_copy_priv() is called and
tmp->tx_cq will be freed on the error path of mlx4_en_copy_priv().
After that mlx4_en_alloc_resources() is called and there is a dereference
of &tmp->tx_cq[t][i] in mlx4_en_alloc_resources(), which could lead to
a use after free problem on failure of mlx4_en_copy_priv().

Fix this bug by adding a check of mlx4_en_copy_priv()

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_MLX4_EN=m show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: ec25bc04ed8e ("net/mlx4_en: Add resilience in low memory systems")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 3f6d5c384637..f1c10f2bda78 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -2286,9 +2286,14 @@ int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
 				bool carry_xdp_prog)
 {
 	struct bpf_prog *xdp_prog;
-	int i, t;
+	int i, t, ret;
 
-	mlx4_en_copy_priv(tmp, priv, prof);
+	ret = mlx4_en_copy_priv(tmp, priv, prof);
+	if (ret) {
+		en_warn(priv, "%s: mlx4_en_copy_priv() failed, return\n",
+			__func__);
+		return ret;
+	}
 
 	if (mlx4_en_alloc_resources(tmp)) {
 		en_warn(priv,
-- 
2.25.1


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

* Re: [PATCH] net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources()
  2021-11-30 16:44 [PATCH] net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources() Zhou Qingyang
@ 2021-12-01  9:27 ` Leon Romanovsky
  2021-12-02  3:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2021-12-01  9:27 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, Tariq Toukan, David S. Miller, Jakub Kicinski,
	Eugenia Emantayev, netdev, linux-rdma, linux-kernel

On Wed, Dec 01, 2021 at 12:44:38AM +0800, Zhou Qingyang wrote:
> In mlx4_en_try_alloc_resources(), mlx4_en_copy_priv() is called and
> tmp->tx_cq will be freed on the error path of mlx4_en_copy_priv().
> After that mlx4_en_alloc_resources() is called and there is a dereference
> of &tmp->tx_cq[t][i] in mlx4_en_alloc_resources(), which could lead to
> a use after free problem on failure of mlx4_en_copy_priv().
> 
> Fix this bug by adding a check of mlx4_en_copy_priv()
> 
> This bug was found by a static analyzer. The analysis employs
> differential checking to identify inconsistent security operations
> (e.g., checks or kfrees) between two code paths and confirms that the
> inconsistent operations are not recovered in the current function or
> the callers, so they constitute bugs.
> 
> Note that, as a bug found by static analysis, it can be a false
> positive or hard to trigger. Multiple researchers have cross-reviewed
> the bug.
> 
> Builds with CONFIG_MLX4_EN=m show no new warnings,
> and our static analyzer no longer warns about this code.
> 
> Fixes: ec25bc04ed8e ("net/mlx4_en: Add resilience in low memory systems")
> Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
> ---
>  drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

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

* Re: [PATCH] net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources()
  2021-11-30 16:44 [PATCH] net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources() Zhou Qingyang
  2021-12-01  9:27 ` Leon Romanovsky
@ 2021-12-02  3:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-02  3:10 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, tariqt, davem, kuba, eugenia, netdev, linux-rdma, linux-kernel

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  1 Dec 2021 00:44:38 +0800 you wrote:
> In mlx4_en_try_alloc_resources(), mlx4_en_copy_priv() is called and
> tmp->tx_cq will be freed on the error path of mlx4_en_copy_priv().
> After that mlx4_en_alloc_resources() is called and there is a dereference
> of &tmp->tx_cq[t][i] in mlx4_en_alloc_resources(), which could lead to
> a use after free problem on failure of mlx4_en_copy_priv().
> 
> Fix this bug by adding a check of mlx4_en_copy_priv()
> 
> [...]

Here is the summary with links:
  - net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources()
    https://git.kernel.org/netdev/net/c/addad7643142

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-12-02  3:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 16:44 [PATCH] net/mlx4_en: Fix an use-after-free bug in mlx4_en_try_alloc_resources() Zhou Qingyang
2021-12-01  9:27 ` Leon Romanovsky
2021-12-02  3:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.