Commit c1b62057 authored by Ilya Dryomov's avatar Ilya Dryomov
Browse files

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: default avatarIlya Dryomov <idryomov@gmail.com>
Reviewed-by: default avatarJason Dillaman <dillaman@redhat.com>
Reviewed-by: default avatarDongsheng Yang <dongsheng.yang@easystack.cn>
parent b948ad78
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -706,10 +706,17 @@ static int rbd_ioctl_set_ro(struct rbd_device *rbd_dev, unsigned long arg)
	if (get_user(ro, (int __user *)arg))
		return -EFAULT;

	/* Snapshots can't be marked read-write */
	if (rbd_is_snap(rbd_dev) && !ro)
	/*
	 * Both images mapped read-only and snapshots can't be marked
	 * read-write.
	 */
	if (!ro) {
		if (rbd_is_ro(rbd_dev))
			return -EROFS;

		rbd_assert(!rbd_is_snap(rbd_dev));
	}

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