linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Hillf Danton <hdanton@sina.com>
Cc: syzbot <syzbot+cc6fc752b3819e082d0c@syzkaller.appspotmail.com>,
	dledford@redhat.com, leon@kernel.org,
	linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
	syzkaller-bugs@googlegroups.com
Subject: Re: KASAN: use-after-free Read in ucma_close (2)
Date: Fri, 11 Sep 2020 08:57:50 -0300	[thread overview]
Message-ID: <20200911115750.GA1137957@ziepe.ca> (raw)
In-Reply-To: <20200911041640.20652-1-hdanton@sina.com>

On Fri, Sep 11, 2020 at 12:16:40PM +0800, Hillf Danton wrote:
> Detect race destroying ctx in order to avoid UAF.
> 
> +++ b/drivers/infiniband/core/ucma.c
> @@ -625,6 +625,10 @@ static ssize_t ucma_destroy_id(struct uc
>  		return PTR_ERR(ctx);
>  
>  	mutex_lock(&ctx->file->mut);
> +	if (ctx->destroying == 1) {
> +		mutex_unlock(&ctx->file->mut);
> +		return -ENXIO;
> +	}
>  	ctx->destroying = 1;
>  	mutex_unlock(&ctx->file->mut);
>  
> @@ -1826,6 +1830,8 @@ static int ucma_close(struct inode *inod
>  
>  	mutex_lock(&file->mut);
>  	list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) {
> +		if (ctx->destroying == 1)
> +			continue;
>  		ctx->destroying = 1;
>  		mutex_unlock(&file->mut);
>  

ucma_destroy_id() is called from write() and ucma_close is release(),
so there is no way these can race?

Jason

  parent reply	other threads:[~2020-09-11 11:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 14:09 KASAN: use-after-free Read in ucma_close (2) syzbot
     [not found] ` <20200911041640.20652-1-hdanton@sina.com>
2020-09-11 11:57   ` Jason Gunthorpe [this message]
     [not found]   ` <20200911152017.18644-1-hdanton@sina.com>
2020-09-11 17:01     ` Jason Gunthorpe
     [not found]     ` <20200912013514.18380-1-hdanton@sina.com>
2020-09-14 15:01       ` Jason Gunthorpe
2020-09-11 12:02 ` Jason Gunthorpe
2020-09-11 15:49   ` syzbot
2020-09-11 18:19 ` Jason Gunthorpe
2020-09-11 20:53   ` syzbot

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=20200911115750.GA1137957@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=dledford@redhat.com \
    --cc=hdanton@sina.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=syzbot+cc6fc752b3819e082d0c@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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;
as well as URLs for NNTP newsgroup(s).