linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Miaoqian Lin <linmq006@gmail.com>
Cc: "Md. Haris Iqbal" <haris.iqbal@ionos.com>,
	Jack Wang <jinpu.wang@ionos.com>, Jason Gunthorpe <jgg@ziepe.ca>,
	Danil Kipnis <danil.kipnis@cloud.ionos.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA/rtrs: Fix double free in alloc_clt
Date: Sun, 23 Jan 2022 12:44:49 +0200	[thread overview]
Message-ID: <Ye0xoRrzREjEmqGp@unreal> (raw)
In-Reply-To: <20220120103714.32108-1-linmq006@gmail.com>

On Thu, Jan 20, 2022 at 10:37:14AM +0000, Miaoqian Lin wrote:
> Callback function rtrs_clt_dev_release() in put_device()
> calls kfree(clt); to free memory. We shouldn't call kfree(clt) again.
> 
> Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/infiniband/ulp/rtrs/rtrs-clt.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 7c3f98e57889..61723f48fbd4 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -2741,7 +2741,7 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num,
>  	err = device_register(&clt->dev);
>  	if (err) {
>  		put_device(&clt->dev);
> -		goto err;
> +		goto err_free_cpu;
>  	}
>  
>  	clt->kobj_paths = kobject_create_and_add("paths", &clt->dev.kobj);
> @@ -2764,6 +2764,9 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num,
>  err:
>  	free_percpu(clt->pcpu_path);
>  	kfree(clt);
> +	clt->pcpu_path = NULL;

Like Jinpu said, it will crash, you are trying to access clt after kfree.

Thanks

> +err_free_cpu:
> +	free_percpu(clt->pcpu_path);
>  	return ERR_PTR(err);
>  }
>  
> -- 
> 2.17.1
> 

      parent reply	other threads:[~2022-01-23 10:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 10:37 [PATCH] RDMA/rtrs: Fix double free in alloc_clt Miaoqian Lin
2022-01-20 14:06 ` Jinpu Wang
2022-01-23 10:44 ` Leon Romanovsky [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=Ye0xoRrzREjEmqGp@unreal \
    --to=leon@kernel.org \
    --cc=danil.kipnis@cloud.ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@ionos.com \
    --cc=linmq006@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).