Hello! This is second version of the patches to add config option to not allow writing to mounted block devices. For motivation why this is interesting see patch 1/6. I've been testing the patches more extensively this time and I've found couple of things that get broken by disallowing writes to mounted block devices: 1) Bind mounts get broken because get_tree_bdev() / mount_bdev() first try to claim the bdev before searching whether it is already mounted. Patch 6 reworks the mount code to avoid this problem. 2) btrfs mounting is likely having the same problem as 1). It should be fixable AFAICS but for now I've left it alone until we settle on the rest of the series. 3) "mount -o loop" gets broken because util-linux keeps the loop device open read-write when attempting to mount it. Hopefully fixable within util-linux. 4) resize2fs online resizing gets broken because it tries to open the block device read-write only to call resizing ioctl. Trivial to fix within e2fsprogs. Likely there will be other breakage I didn't find yet but overall the breakage looks minor enough that the option might be useful. Definitely good enough for syzbot fuzzing and likely good enough for hardening of systems with more tightened security. This patch set is based on the patches making blkdev_get_by_*() return bdev_handle [1]. Changes since v1: * Added kernel cmdline argument to toggle whether writing to mounted block devices is allowed or not * Fixed handling of partitions * Limit write blocking only to devices open with explicit BLK_OPEN_BLOCK_WRITES flag Honza [1] https://lore.kernel.org/all/20230629165206.383-1-jack@xxxxxxx Previous versions: v1: https://lore.kernel.org/all/20230612161614.10302-1-jack@xxxxxxx