linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Jason Yan <yanaijie@huawei.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>, Ming Lei <ming.lei@redhat.com>,
	Jan Kara <jack@suse.cz>, Dan Carpenter <dan.carpenter@oracle.com>,
	Hulk Robot <hulkci@huawei.com>,
	Sedat Dilek <sedat.dilek@gmail.com>
Subject: Re: [PATCH v7] block: Fix use-after-free in blkdev_get()
Date: Tue, 16 Jun 2020 10:33:37 -0600	[thread overview]
Message-ID: <4fbfbf0b-8587-0376-a869-817157e8bfd7@kernel.dk> (raw)
In-Reply-To: <20200616121655.3516305-1-yanaijie@huawei.com>

On 6/16/20 6:16 AM, Jason Yan wrote:
> In blkdev_get() we call __blkdev_get() to do some internal jobs and if
> there is some errors in __blkdev_get(), the bdput() is called which
> means we have released the refcount of the bdev (actually the refcount of
> the bdev inode). This means we cannot access bdev after that point. But
> acctually bdev is still accessed in blkdev_get() after calling
> __blkdev_get(). This results in use-after-free if the refcount is the
> last one we released in __blkdev_get(). Let's take a look at the
> following scenerio:
> 
>   CPU0            CPU1                    CPU2
> blkdev_open     blkdev_open           Remove disk
>                   bd_acquire
> 		  blkdev_get
> 		    __blkdev_get      del_gendisk
> 					bdev_unhash_inode
>   bd_acquire          bdev_get_gendisk
>     bd_forget           failed because of unhashed
> 	  bdput
> 	              bdput (the last one)
> 		        bdev_evict_inode
> 
> 	  	    access bdev => use after free

I've queued this up for 5.8, thanks.

-- 
Jens Axboe


      reply	other threads:[~2020-06-16 16:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16 12:16 [PATCH v7] block: Fix use-after-free in blkdev_get() Jason Yan
2020-06-16 16:33 ` Jens Axboe [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=4fbfbf0b-8587-0376-a869-817157e8bfd7@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=dan.carpenter@oracle.com \
    --cc=hch@lst.de \
    --cc=hulkci@huawei.com \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=sedat.dilek@gmail.com \
    --cc=yanaijie@huawei.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).