2022-09-30 07:31:09

by Jianglei Nie

[permalink] [raw]
Subject: [PATCH] bnx2x: fix potential memory leak in bnx2x_tpa_stop()

bnx2x_tpa_stop() allocates a memory chunk from new_data with
bnx2x_frag_alloc(). The new_data should be freed when gets some error.
But when "pad + len > fp->rx_buf_size" is true, bnx2x_tpa_stop() returns
without releasing the new_data, which will lead to a memory leak.

We should free the new_data with bnx2x_frag_free() when "pad + len >
fp->rx_buf_size" is true.

Fixes: 07b0f00964def8af9321cfd6c4a7e84f6362f728 ("bnx2x: fix possible
panic under memory stress")
Signed-off-by: Jianglei Nie <[email protected]>
---
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 712b5595bc39..24bfc65e28e1 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -789,6 +789,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
BNX2X_ERR("skb_put is about to fail... pad %d len %d rx_buf_size %d\n",
pad, len, fp->rx_buf_size);
bnx2x_panic();
+ bnx2x_frag_free(fp, new_data);
return;
}
#endif
--
2.25.1


2022-10-03 12:19:58

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH] bnx2x: fix potential memory leak in bnx2x_tpa_stop()

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

On Fri, 30 Sep 2022 14:28:43 +0800 you wrote:
> bnx2x_tpa_stop() allocates a memory chunk from new_data with
> bnx2x_frag_alloc(). The new_data should be freed when gets some error.
> But when "pad + len > fp->rx_buf_size" is true, bnx2x_tpa_stop() returns
> without releasing the new_data, which will lead to a memory leak.
>
> We should free the new_data with bnx2x_frag_free() when "pad + len >
> fp->rx_buf_size" is true.
>
> [...]

Here is the summary with links:
- bnx2x: fix potential memory leak in bnx2x_tpa_stop()
https://git.kernel.org/netdev/net/c/b43f9acbb894

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