From: Leon Romanovsky <leon@kernel.org>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
Jason Gunthorpe <jgg@mellanox.com>,
Doug Ledford <dledford@redhat.com>
Subject: Re: [PATCH] ucma: fix a use-after-free in ucma_resolve_ip()
Date: Thu, 13 Sep 2018 08:49:15 +0300 [thread overview]
Message-ID: <20180913054915.GF5257@mtr-leonro.mtl.com> (raw)
In-Reply-To: <20180912232744.12693-1-xiyou.wangcong@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1558 bytes --]
On Wed, Sep 12, 2018 at 04:27:44PM -0700, Cong Wang wrote:
> There is a race condition between ucma_close() and ucma_resolve_ip():
>
> CPU0 CPU1
> ucma_resolve_ip(): ucma_close():
>
> ctx = ucma_get_ctx(file, cmd.id);
>
> list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) {
> mutex_lock(&mut);
> idr_remove(&ctx_idr, ctx->id);
> mutex_unlock(&mut);
> ...
> mutex_lock(&mut);
> if (!ctx->closing) {
> mutex_unlock(&mut);
> rdma_destroy_id(ctx->cm_id);
> ...
> ucma_free_ctx(ctx);
>
> ret = rdma_resolve_addr();
> ucma_put_ctx(ctx);
>
> Before idr_remove(), ucma_get_ctx() could still find the ctx
> and after rdma_destroy_id(), rdma_resolve_addr() may still
> access id_priv pointer. Also, ucma_put_ctx() may use ctx after
> ucma_free_ctx() too.
>
> ucma_close() should call ucma_put_ctx() too which tests the
> refcnt and waits for the last one releasing it. The similar
> pattern is already used by ucma_destroy_id().
>
> Reported-and-tested-by: syzbot+da2591e115d57a9cbb8b@syzkaller.appspotmail.com
> Reported-by: syzbot+cfe3c1e8ef634ba8964b@syzkaller.appspotmail.com
> Cc: Jason Gunthorpe <jgg@mellanox.com>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Leon Romanovsky <leon@kernel.org>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> drivers/infiniband/core/ucma.c | 2 ++
> 1 file changed, 2 insertions(+)
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next prev parent reply other threads:[~2018-09-13 5:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-12 23:27 [PATCH] ucma: fix a use-after-free in ucma_resolve_ip() Cong Wang
2018-09-13 5:49 ` Leon Romanovsky [this message]
2018-09-13 17:05 ` Doug Ledford
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=20180913054915.GF5257@mtr-leonro.mtl.com \
--to=leon@kernel.org \
--cc=dledford@redhat.com \
--cc=jgg@mellanox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=xiyou.wangcong@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