All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Cc: dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] infiniband/core: Fix a use after free in cm_work_handler
Date: Thu, 11 Mar 2021 11:22:03 +0200	[thread overview]
Message-ID: <YEnhO9EXgI8pwVD2@unreal> (raw)
In-Reply-To: <20210311022153.3757-1-lyl2019@mail.ustc.edu.cn>

On Wed, Mar 10, 2021 at 06:21:53PM -0800, Lv Yunlong wrote:
> In cm_work_handler, it calls destory_cm_id() to release
> the initial reference of cm_id_priv taken by iw_create_cm_id()
> and free the cm_id_priv. After destory_cm_id(), iwcm_deref_id
> (cm_id_priv) will be called and cause a use after free.
>
> Fixes: 59c68ac31e15a ("iw_cm: free cm_id resources on the last deref")
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
>  drivers/infiniband/core/iwcm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
> index da8adadf4755..cb6b4ac45e21 100644
> --- a/drivers/infiniband/core/iwcm.c
> +++ b/drivers/infiniband/core/iwcm.c
> @@ -1035,8 +1035,10 @@ static void cm_work_handler(struct work_struct *_work)
>
>  		if (!test_bit(IWCM_F_DROP_EVENTS, &cm_id_priv->flags)) {
>  			ret = process_event(cm_id_priv, &levent);
> -			if (ret)
> +			if (ret) {
>  				destroy_cm_id(&cm_id_priv->id);
> +				return;

The destroy_cm_id() is called to free ->id and not cm_id_priv. This "return"
leaks cm_id_priv now and what "a use after free" do you see?

> +			}
>  		} else
>  			pr_debug("dropping event %d\n", levent.event);
>  		if (iwcm_deref_id(cm_id_priv))
> --
> 2.25.1
>
>

  reply	other threads:[~2021-03-11  9:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  2:21 [PATCH] infiniband/core: Fix a use after free in cm_work_handler Lv Yunlong
2021-03-11  9:22 ` Leon Romanovsky [this message]
2021-03-11 10:29   ` lyl2019
2021-03-11 11:05     ` Leon Romanovsky
2021-03-11 12:03       ` lyl2019
2021-03-11 14:12         ` Leon Romanovsky

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=YEnhO9EXgI8pwVD2@unreal \
    --to=leon@kernel.org \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lyl2019@mail.ustc.edu.cn \
    /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.