mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@nvidia.com>
To: Jinvas <jinvas@126.com>,
	saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com,
	leonro@nvidia.com, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org, horms@kernel.org,
	alexious@zju.edu.cn
Subject: Re: [PATCH net v2 1/1] net/mlx5e: fix NULL pointer dereference in arfs_create_groups()
Date: Mon, 16 Nov 2026 23:20:14 +0200	[thread overview]
Message-ID: <08161b3e-9838-45da-8842-dd003269311f@nvidia.com> (raw)
In-Reply-To: <20261116130406.1171-2-jinvas@126.com>



On 16/11/2026 15:04, Jinvas wrote:
> arfs_create_groups() creates up to two flow groups in ft->g[], and
> increments ft->num_groups for each group that was created successfully.
> If creating the second group fails, the error path frees ft->g and sets
> it to NULL, but leaves ft->num_groups at 1.
> 
> The only caller, arfs_create_table(), calls mlx5e_destroy_flow_table() on
> the error path, which calls mlx5e_destroy_groups(). The latter walks
> ft->g[] from ft->num_groups - 1 down to 0 and dereferences ft->g[0].
> Since ft->g was freed and set to NULL, this is a NULL pointer
> dereference, and the kernel oopses.
> 
> The same error path also leaks the flow group that was created
> successfully before the failure, since ft->g is freed without the group
> being destroyed.
> 
> Freeing ft->g here was added by commit 3c6d5189246f ("net/mlx5e: fix a
> double-free in arfs_create_groups"). Before that commit, the group
> failure path did not touch ft->g at all, so the caller destroyed the
> flow groups that had been created and then freed the array. That
> commit fixed a double free in the allocation failure path by freeing
> ft->g here as well, and in doing so changed the group failure path
> too.
> 
> Rather than also resetting ft->num_groups, leave the free of ft->g to
> the caller: mlx5e_destroy_flow_table() frees ft->g exactly once, and
> also destroys the flow groups that were created. This fixes the NULL
> pointer dereference and the leak, while keeping the double free fixed.
> 
> This also makes the error handling of this function consistent with the
> rest of the driver, e.g. mlx5e_create_l2_table().

Thanks for the fix, and for the detailed analysis.
Doesn't seem accurate. mlx5e_create_l2_table() does the opposite. Better 
drop the sentence.

> 
> Fixes: 3c6d5189246f ("net/mlx5e: fix a double-free in arfs_create_groups")

Say in the commit message how the bug was found, whether
the fix was tested, and on which device. A trimmed oops maybe as well.
This info is currently in the cover letter.

> Signed-off-by: Jinvas <jinvas@126.com>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c
> index c5e62d7..7888d38 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c
> @@ -267,7 +267,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
>   	in = kvzalloc(inlen, GFP_KERNEL);
>   	if (!in) {
>   		err = -ENOMEM;
> -		goto err_free_g;
> +		goto err_free_in;

nit: nothing needs to be freed here anymore, so a plain
"return -ENOMEM;" is simpler than jumping to a label that frees "in".

The fix itself looks right.

>   	}
>   
>   	mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
> @@ -338,9 +338,6 @@ err_clean_group:
>   	ft->g[ft->num_groups] = NULL;
>   err_free_in:
>   	kvfree(in);
> -err_free_g:
> -	kfree(ft->g);
> -	ft->g = NULL;
>   	return err;
>   }
>   


      reply	other threads:[~2026-11-16 21:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 13:04 [PATCH net v2 0/1] " Jinvas
2026-11-16 13:04 ` [PATCH net v2 1/1] " Jinvas
2026-11-16 21:20   ` Tariq Toukan [this message]

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=08161b3e-9838-45da-8842-dd003269311f@nvidia.com \
    --to=tariqt@nvidia.com \
    --cc=alexious@zju.edu.cn \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jinvas@126.com \
    --cc=kuba@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®