From: Gulam Mohamed Date: Fri, 14 May 2021 13:18:42 +0000 (+0200) Subject: block: fix a race between del_gendisk and BLKRRPART X-Git-Tag: v5.10.42~66 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b0f5d4891ea3a80ad619312355494dc25073e219;p=thirdparty%2Fkernel%2Fstable.git block: fix a race between del_gendisk and BLKRRPART [ Upstream commit bc6a385132601c29a6da1dbf8148c0d3c9ad36dc ] When BLKRRPART is called concurrently with del_gendisk, the partitions rescan can create a stale partition that will never be be cleaned up. Fix this by checking the the disk is up before rescanning partitions while under bd_mutex. Signed-off-by: Gulam Mohamed [hch: split from a larger patch] Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei Link: https://lore.kernel.org/r/20210514131842.1600568-3-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- diff --git a/fs/block_dev.c b/fs/block_dev.c index cacea6bafc229..29f020c4b2d0d 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1408,6 +1408,9 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate) lockdep_assert_held(&bdev->bd_mutex); + if (!(disk->flags & GENHD_FL_UP)) + return -ENXIO; + rescan: ret = blk_drop_partitions(bdev); if (ret)