Re: [PATCH v2] loop: block changing lo_offset/lo_sizelimit on mounted device
From: Christoph Hellwig
Date: Tue Mar 31 2026 - 03:23:05 EST
On Tue, Mar 31, 2026 at 11:16:48AM +0530, Deepanshu Kartikey wrote:
> LOOP_SET_STATUS{64} allows changing lo_offset and shrinking
> lo_sizelimit while a filesystem is mounted on the loop device.
> This effectively mutates the data visible to the mounted filesystem,
> which is equivalent to writing directly to the block device.
>
> When CONFIG_BLK_DEV_WRITE_MOUNTED is disabled, direct writes to a
> mounted block device are blocked. However, LOOP_SET_STATUS{64}
> bypasses this protection because it modifies the loop configuration
> through an ioctl rather than opening the block device for writing.
>
> Fix this by checking bdev_writes_blocked() before allowing changes
> to lo_offset or shrinking lo_sizelimit. If the loop device has
> writes blocked, return -EBUSY. Increasing lo_sizelimit is still
> allowed since growing the device is harmless and has legitimate
> use cases such as online resize.
>
> Move bdev_writes_blocked() from block/bdev.c to
> include/linux/blk_types.h as a static inline function so it can
> be used from the loop driver without exporting a symbol.
I still think this is a very bad idea for the reasons explained before.
And I would not be surprised if this breaks something in blktests or
xfstests as they heavily rely on resizing block devices. Did you
do full runs of those? Especially with xfs and btrfs for xfstests
as they do a lot more loop based tests?