mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: dinghao.liu@zju.edu.cn
To: "Tariq Toukan" <ttoukan.linux@gmail.com>
Cc: "Saeed Mahameed" <saeedm@nvidia.com>,
	"Leon Romanovsky" <leon@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Zhengchao Shao" <shaozhengchao@huawei.com>,
	"Rahul Rameshbabu" <rrameshbabu@nvidia.com>,
	"Simon Horman" <horms@kernel.org>,
	"Tariq Toukan" <tariqt@nvidia.com>, "Aya Levin" <ayal@nvidia.com>,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/mlx5e: fix a potential double-free in fs_any_create_groups
Date: Tue, 28 Nov 2023 17:15:03 +0800 (GMT+08:00)	[thread overview]
Message-ID: <18fac281.ae29.18c1535e9b4.Coremail.dinghao.liu@zju.edu.cn> (raw)
In-Reply-To: <3d3b6a1f-40b6-45b5-a899-d01acb91213d@gmail.com>

> 
> On 28/11/2023 10:28, Dinghao Liu wrote:
> > When kcalloc() for ft->g succeeds but kvzalloc() for in fails,
> > fs_any_create_groups() will free ft->g. However, its caller
> > fs_any_create_table() will free ft->g again through calling
> > mlx5e_destroy_flow_table(), which will lead to a double-free.
> > Fix this by removing the kfree(ft->g) in fs_any_create_groups().
> > 
> > Fixes: 0f575c20bf06 ("net/mlx5e: Introduce Flow Steering ANY API")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >   drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c | 1 -
> >   1 file changed, 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> > index be83ad9db82a..b222d23bfb9a 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
> > @@ -434,7 +434,6 @@ static int fs_any_create_groups(struct mlx5e_flow_table *ft)
> >   	ft->g = kcalloc(MLX5E_FS_UDP_NUM_GROUPS, sizeof(*ft->g), GFP_KERNEL);
> >   	in = kvzalloc(inlen, GFP_KERNEL);
> >   	if  (!in || !ft->g) {
> > -		kfree(ft->g);
> >   		kvfree(in);
> >   		return -ENOMEM;
> >   	}
> 
> Function fs_any_create_groups should not return failure without cleaning 
> itself up. This is not the right fix.
> Freeing ft->g and setting it to NULL will do it, and will avoid the 
> double free.

Thanks for your advice! I will resend a new patch soon.

Regards,
Dinghao

      reply	other threads:[~2023-11-28  9:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28  8:28 Dinghao Liu
2023-11-28  8:58 ` Tariq Toukan
2023-11-28  9:15   ` dinghao.liu [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=18fac281.ae29.18c1535e9b4.Coremail.dinghao.liu@zju.edu.cn \
    --to=dinghao.liu@zju.edu.cn \
    --cc=ayal@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rrameshbabu@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=shaozhengchao@huawei.com \
    --cc=tariqt@nvidia.com \
    --cc=ttoukan.linux@gmail.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®