From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Jiangshan Yi <yijiangshan@kylinos.cn>,
skalluru@marvell.com, manishc@marvell.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: yuvalmin@broadcom.com, dmitry@broadcom.com, ariele@broadcom.com,
eilong@broadcom.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, 13667453960@163.com,
Sashiko <sashiko-bot@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] bnx2x: fix NULL pointer dereference in bnx2x_free_mem_bp()
Date: Mon, 17 Aug 2026 14:11:36 +0100 [thread overview]
Message-ID: <a7360a7e-6c42-4891-a01c-a349d1cb803a@linux.dev> (raw)
In-Reply-To: <20260817033332.175665-1-yijiangshan@kylinos.cn>
On 17/08/2026 04:33, Jiangshan Yi wrote:
> bnx2x_alloc_mem_bp() sets bp->fp_array_size before allocating bp->fp.
> If the fp allocation fails, the error path calls bnx2x_free_mem_bp(),
> which dereferences bp->fp in a loop bounded by the non-zero
> bp->fp_array_size, causing a NULL pointer dereference.
>
> Move the bp->fp_array_size assignment to after bp->fp is set, and
> add a NULL guard in bnx2x_free_mem_bp().
>
> Fixes: c3146eb676e7c ("bnx2x: Correct memory preparation and release")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260815122149.951215-1-yijiangshan%40kylinos.cn
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
> ---
> drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> index 5b2640bd31c3..d84d1845a096 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> @@ -4712,8 +4712,10 @@ void bnx2x_free_mem_bp(struct bnx2x *bp)
> {
> int i;
>
> - for (i = 0; i < bp->fp_array_size; i++)
> - kfree(bp->fp[i].tpa_info);
> + if (bp->fp) {
there is no need to put this defensive code ...
> + for (i = 0; i < bp->fp_array_size; i++)
> + kfree(bp->fp[i].tpa_info);
> + }
> kfree(bp->fp);
> kfree(bp->sp_objs);
> kfree(bp->fp_stats);
> @@ -4742,13 +4744,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);
> + BNX2X_DEV_INFO("fp_array_size %d\n", fp_array_size);
>
> - fp = kzalloc_objs(*fp, bp->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;
... when you have fixed the root cause of the issue
> for (i = 0; i < bp->fp_array_size; i++) {
> fp[i].tpa_info =
> kzalloc_objs(struct bnx2x_agg_info,
next prev parent reply other threads:[~2026-08-17 13:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 3:33 [PATCH] bnx2x: fix NULL pointer dereference in bnx2x_free_mem_bp() Jiangshan Yi
2026-08-17 13:11 ` Vadim Fedorenko [this message]
2026-08-17 15:08 ` Jiangshan Yi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a7360a7e-6c42-4891-a01c-a349d1cb803a@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=13667453960@163.com \
--cc=andrew+netdev@lunn.ch \
--cc=ariele@broadcom.com \
--cc=davem@davemloft.net \
--cc=dmitry@broadcom.com \
--cc=edumazet@google.com \
--cc=eilong@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manishc@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=skalluru@marvell.com \
--cc=stable@vger.kernel.org \
--cc=yijiangshan@kylinos.cn \
--cc=yuvalmin@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.