Skip to contentSkip to conversation

bnx2x: fix null pointer dereference in bnx2x_free_mem_bp()

PATCH Applied Abdun Nihaal 3 participants 3 messages Jul 7 – Jul 21

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bnx2x: fix null pointer dereference in bnx2x_free_mem_bp()

In one of the error path in bnx2x_alloc_mem_bp(), bnx2x_free_mem_bp() may be called with bp->fp uninitialized. And so, there could be a null pointer dereference in bnx2x_free_mem_bp(). Fix that by initializing the fp_array_size after the bp->fp pointer is correctly initialized.

Fixes c3146eb676e7 ("bnx2x: Correct memory preparation and release")

---
Compile tested only.
Thanks to Simon Horman for pointing out the Sashiko review.

v1->v2:
- Add the correct Reported-by tag for Sashiko as suggested by Maciej Fijalkowski. Also added Maciej's Reviewed-by tag.
- Simplify the fix by initializing the fp_array_size later, as suggested by Paolo Abeni.

Link to v1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +4 -4
index 5b2640bd31c3..5a9742fd3ddf 100644
@@ -4742,13 +4742,13 @@ int bnx2x_alloc_mem_bp(struct bnx2x *bp)
 
 	/* fp array: RSS plus CNIC related L2 queues */
 	fp_array_size = BNX2X_MAX_RSS_COUNT(bp) + CNIC_SUPPORT(bp);
-	bp->fp_array_size = fp_array_size;
-	BNX2X_DEV_INFO("fp_array_size %d\n", bp->fp_array_size);
-
-	fp = kzalloc_objs(*fp, bp->fp_array_size);
+	BNX2X_DEV_INFO("fp_array_size %d\n", fp_array_size);
+	fp = kzalloc_objs(*fp, fp_array_size);
 	if (!fp)
 		goto alloc_err;
 	bp->fp = fp;
+	bp->fp_array_size = fp_array_size;
+
 	for (i = 0; i < bp->fp_array_size; i++) {
 		fp[i].tpa_info =
 			kzalloc_objs(struct bnx2x_agg_info,
Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 14 lines · Abdun Nihaal

In one of the error path in bnx2x_alloc_mem_bp(), bnx2x_free_mem_bp() may be called with bp->fp uninitialized. And so, there could be a null pointer dereference in bnx2x_free_mem_bp(). Fix that by initializing the fp_array_size after the bp->fp pointer is correctly initialized.

Fixes c3146eb676e7 ("bnx2x: Correct memory preparation and release")

---
Compile tested only.
Thanks to Simon Horman for pointing out the Sashiko review.

Quoted 7 lines

v1->v2:
- Add the correct Reported-by tag for Sashiko as suggested by Maciej Fijalkowski. Also added Maciej's Reviewed-by tag.
- Simplify the fix by initializing the fp_array_size later, as suggested by Paolo Abeni.

Link to v1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

#2 lore raw
In reply to Abdun Nihaal
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 5 lines · On Tue, 7 Jul 2026 11:16:16 +0530 you wrote:

In one of the error path in bnx2x_alloc_mem_bp(), bnx2x_free_mem_bp() may be called with bp->fp uninitialized. And so, there could be a null pointer dereference in bnx2x_free_mem_bp(). Fix that by initializing the fp_array_size after the bp->fp pointer is correctly initialized.

Quoted 7 lines
Fixes c3146eb676e7 ("bnx2x: Correct memory preparation and release")

[...]

Here is the summary with links:
- [v2,net] bnx2x: fix null pointer dereference in bnx2x_free_mem_bp()

    https://git.kernel.org/netdev/net-next/c/e354f7d60f14

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html