Message ID | 20200608020557.31668-1-yanaijie@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v4] block: Fix use-after-free in blkdev_get() | expand |
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
Can you dig into the history for a proper fixes tag?
Hi Christoph, 在 2020/6/8 14:15, Christoph Hellwig 写道: > Looks good, > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > Can you dig into the history for a proper fixes tag? > This one started to accessing bdev after __blkdev_get(). So I think it may be a proper fixes tag: Fixes: e525fd89d380 ("block: make blkdev_get/put() handle exclusive access") Thanks, Jason > . >
On Mon, Jun 8, 2020 at 8:18 AM Christoph Hellwig <hch@lst.de> wrote: > > Looks good, > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > Can you dig into the history for a proper fixes tag? [ CC Dan ] Dan gave the hint for the Fixes: tag in reply to the first patch: > The Fixes tag is a good idea though: > > Fixes: 89e524c04fa9 ("loop: Fix mount(2) failure due to race with LOOP_SET_FD") > It broke last July. Before that, we used to check if __blkdev_get() > failed before dereferencing "bdev". - Sedat -
On Mon, Jun 8, 2020 at 8:47 AM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > On Mon, Jun 8, 2020 at 8:18 AM Christoph Hellwig <hch@lst.de> wrote: > > > > Looks good, > > > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > > > Can you dig into the history for a proper fixes tag? > > [ CC Dan ] > > Dan gave the hint for the Fixes: tag in reply to the first patch: > > > The Fixes tag is a good idea though: > > > > Fixes: 89e524c04fa9 ("loop: Fix mount(2) failure due to race with LOOP_SET_FD") > > > It broke last July. Before that, we used to check if __blkdev_get() > > failed before dereferencing "bdev". > Here is the Link. https://www.spinics.net/lists/linux-block/msg54825.html - Sedat -
On Mon, Jun 8, 2020 at 8:52 AM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > On Mon, Jun 8, 2020 at 8:47 AM Sedat Dilek <sedat.dilek@gmail.com> wrote: > > > > On Mon, Jun 8, 2020 at 8:18 AM Christoph Hellwig <hch@lst.de> wrote: > > > > > > Looks good, > > > > > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > > > > > Can you dig into the history for a proper fixes tag? > > > > [ CC Dan ] > > > > Dan gave the hint for the Fixes: tag in reply to the first patch: > > > > > The Fixes tag is a good idea though: > > > > > > Fixes: 89e524c04fa9 ("loop: Fix mount(2) failure due to race with LOOP_SET_FD") > > > > > It broke last July. Before that, we used to check if __blkdev_get() > > > failed before dereferencing "bdev". > > > > Here is the Link. > > https://www.spinics.net/lists/linux-block/msg54825.html > Really CC Dan in 3rd attempt. OMG, I need a coffee - urgently. - Sedat -
diff --git a/fs/block_dev.c b/fs/block_dev.c index 47860e589388..08c87db3a92b 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1565,10 +1565,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) */ if (!for_part) { ret = devcgroup_inode_permission(bdev->bd_inode, perm); - if (ret != 0) { - bdput(bdev); + if (ret != 0) return ret; - } } restart: @@ -1637,8 +1635,10 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) goto out_clear; BUG_ON(for_part); ret = __blkdev_get(whole, mode, 1); - if (ret) + if (ret) { + bdput(whole); goto out_clear; + } bdev->bd_contains = whole; bdev->bd_part = disk_get_part(disk, partno); if (!(disk->flags & GENHD_FL_UP) || @@ -1688,7 +1688,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) disk_unblock_events(disk); put_disk_and_module(disk); out: - bdput(bdev); return ret; } @@ -1755,6 +1754,9 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) bdput(whole); } + if (res) + bdput(bdev); + return res; } EXPORT_SYMBOL(blkdev_get);