Skip to content

Commit c1b6205

Browse files
committed
rbd: disallow read-write partitions on images mapped read-only
If an image is mapped read-only, don't allow setting its partition(s) to read-write via BLKROSET: with the previous patch all writes to such images are failed anyway. If an image is mapped read-write, its partition(s) can be set to read-only (and back to read-write) as before. Note that at the rbd level the image will remain writeable: anything sent down by the block layer will be executed, including any write from internal kernel users. Signed-off-by: Ilya Dryomov <[email protected]> Reviewed-by: Jason Dillaman <[email protected]> Reviewed-by: Dongsheng Yang <[email protected]>
1 parent b948ad7 commit c1b6205

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/block/rbd.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,16 @@ static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg)
706706
if (get_user(ro, (int __user *)arg))
707707
return -EFAULT;
708708

709-
/* Snapshots can't be marked read-write */
710-
if (rbd_is_snap(rbd_dev) && !ro)
711-
return -EROFS;
709+
/*
710+
* Both images mapped read-only and snapshots can't be marked
711+
* read-write.
712+
*/
713+
if (!ro) {
714+
if (rbd_is_ro(rbd_dev))
715+
return -EROFS;
716+
717+
rbd_assert(!rbd_is_snap(rbd_dev));
718+
}
712719

713720
/* Let blkdev_roset() handle it */
714721
return -ENOTTY;

0 commit comments

Comments
 (0)