Re: [PATCH] loop: block loop reconfiguration of offset/sizelimit on mounted device

From: Deepanshu Kartikey

Date: Mon Mar 30 2026 - 10:43:22 EST


On Mon, Mar 30, 2026 at 7:08 PM Theodore Tso <tytso@xxxxxxx> wrote:
>
> The patch was missing the...
>
> #ifndef CONFIG_BLK_DEV_WRITE_MOUNTED)
>
> ... in loop.c which was in my original sketch of a patch which I sent
> to Deepanshu.
>
> The intent was to suppress Syzkaller noise. Inherent in my assumption
> was that changing either lo_offset or lo_sizelimit parameter was going
> to mutate the loop device when it was mounted, which was the intent of
> !CONFIG_BLK_DEV_WRITE_MOUNTED. I also assumed that at least for now,
> the only user of !CONFIG_BLK_DEV_WRITE_MOUNTED was syzkaller, since
> there are file systems (in particular ext4) that are commonly in use
> whose userspace utilities fundamentally assume that you can write to
> the block device. Even after we promulgate the tune2fs changes to use
> the new EXT4_IOC_SET_TUNE_SB_PARAM ioctl and we can assume that it is
> common use in deployed kernels, some grub operations still assume they
> can modify the block device where the second-stage grub bootloader is
> located.
>
> In the long term, when ext4 can start assuming that we can suppress
> writes to the block device (and we find a solution to the grub issue),
> we'll probably want to have a way to suppress write access to block
> devices on a per-super basis, without clearing the Kconfig
> CONFIG_BLK_DEV_WRITE_MOUNTED. But that's a problem for another day...
>
> Cheers,
>
> - Ted


Hi Ted, Christoph,

Thank you both for the feedback. Based on your suggestions, I'll
submit a v2 with the following approach:

- Use #ifndef CONFIG_BLK_DEV_WRITE_MOUNTED as Ted originally
intended, since this is meant to suppress syzkaller noise
- Check bd_writers directly instead of exporting
bdev_writes_blocked(), addressing Christoph's concern
- No changes to block/bdev.c or include/linux/blkdev.h, keeping
the patch minimal and limited to drivers/block/loop.c

The check would be:

#ifndef CONFIG_BLK_DEV_WRITE_MOUNTED
if ((lo->lo_offset != info->lo_offset ||
lo->lo_sizelimit != info->lo_sizelimit) &&
lo->lo_device->bd_writers < 0) {
err = -EBUSY;
goto out_unlock;
}
#endif

Regarding Christoph's point about increasing lo_sizelimit being
safe - should I narrow the check to only block shrinking and
offset changes?

Thanks,
Deepanshu