Skip to content

Commit e51900f

Browse files
Chuck Ebberttorvalds
authored andcommitted
block: revert block_dev read-only check
This reverts commit 75f1dc0 ("block: check bdev_read_only() from blkdev_get()"). That commit added stricter checking to make sure devices that were being used read-only were actually opened in that mode. It turns out that the change breaks a bunch of kernel code that opens block devices. Affected systems include dm, md, and the loop device. Because strict checking for read-only opens of block devices was not done before this, the code that opens the devices was opening them read-write even if they were being used read-only. Auditing all that code will take time, and new userspace packages for dm, mdadm, etc. will also be required. Signed-off-by: Chuck Ebbert <cebbert@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a264011 commit e51900f

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎fs/block_dev.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,12 +1215,6 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
12151215

12161216
res = __blkdev_get(bdev, mode, 0);
12171217

1218-
/* __blkdev_get() may alter read only status, check it afterwards */
1219-
if (!res && (mode & FMODE_WRITE) && bdev_read_only(bdev)) {
1220-
__blkdev_put(bdev, mode, 0);
1221-
res = -EACCES;
1222-
}
1223-
12241218
if (whole) {
12251219
/* finish claiming */
12261220
mutex_lock(&bdev->bd_mutex);
@@ -1298,6 +1292,11 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
12981292
if (err)
12991293
return ERR_PTR(err);
13001294

1295+
if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) {
1296+
blkdev_put(bdev, mode);
1297+
return ERR_PTR(-EACCES);
1298+
}
1299+
13011300
return bdev;
13021301
}
13031302
EXPORT_SYMBOL(blkdev_get_by_path);

0 commit comments

Comments
 (0)