e2fsprogs/resize2fs: allow online resizing with CONFIG_BLK_DEV_WRITE_MOUNTED disabled
PATCH 1/1 e2fsprogs/resize2fs: allow online resizing with CONFIG_BLK_DEV_WRITE_MOUNTED disabled
Kernels since version 6.8 have an option CONFIG_BLK_DEV_WRITE_MOUNTED that, if disabled, prevents accidental writes to and data corruption of mounted devices.
This breaks online resizing with resize2fs, as it opens the device with O_RDWR. However, it appears that this is not necessary and by changing it to O_RDONLY, online resizing works again.
See also: https://unix.stackexchange.com/a/796881
resize/main.c +1 -4
@@ -256,7 +256,7 @@ int main (int argc, char ** argv)int force_min_size =0 ;int print_min_size =0 ;int fd, ret; -int open_flags =O_RDWR ; +int open_flags =O_RDONLY ;blk64_t new_size =0 ;blk64_t max_size =0 ;blk64_t min_size =0 ;
@@ -364,9 +364,6 @@ int main (int argc, char ** argv) len =2 * len; } -if (print_min_size) - open_flags =O_RDONLY ; - fd =ext2fs_open_file (device_name, open_flags,0 );if (fd <0 ) { com_err("open", errno, _("while opening %s"),
Quoted 11 lines · Hanno Böck
Kernels since version 6.8 have an option
CONFIG_BLK_DEV_WRITE_MOUNTEDthat, if disabled, prevents accidental writes to and data corruption of mounted devices.This breaks online resizing with resize2fs, as it opens the device with
O_RDWR. However, it appears that this is not necessary and by changing it toO_RDONLY, online resizing works again.See also: https://unix.stackexchange.com/a/796881
Signed-off-by Hanno Böck <[email protected]>
If you try run e2fssprogs's regression test (using "make check"), with your patch applied, you'll find:
% make -j24 ; make -j24 check
...t_mmp_2off: disable MMP using tune2fs: ok
377 tests succeeded 15 tests failed
Tests failed: m_minrootdir r_1024_small_bg r_32to64bit_expand_full r_bigalloc_big_expand r_ext4_small_bg r_fixup_lastbg_big r_fixup_lastbg r_inline_xattr r_min_itable r_move_inode_int_extent r_move_itable r_move_itable_nostride r_move_itable_realloc r_orphan_file r_resize_inode make[1]: *** [Makefile:403: test_post] Error 1
make[1]: Leaving directory '/build/e2fsprogs/tests'
make: *** [Makefile:431: check-recursive] Error 1
Specifically, your change breaks off-line resizes, where the file system is not mounted. E2fsprogs builds on FreeBSD, GNU/Hurd, MacOS, and other operating systems which don't support online resizing, which is a Linux-only feature.
Furthermore, even on Linux, online resizing only supports growing the file system. If you want to shrink the file system, this must be done using off-line resizing, with the file system unmounted.
And as I pointed out on another e-mail thread, fixing resize2fs is not sufficient to disable CONFIG_BLK_DEV_WRITE_MOUNTED and retain full functionality. Specifically, certain file system parameters can be modified using tune2fs while the file system is mounted. Disabling CONFIG_BLK_DEV_WRITE_MOUNTED will break this.
The CONFIG_BLK_DEV_WRITE_MOUNTED option was added specifically to suppress maintainers from downing in Syzbot-generated noise, which will gleefully report "security failures" caused by being able to modify the block device while the file system is mounted. The syzbot scanner runs as root, which means it's great for inflating security reports, at the cost of overloading maintainers who often deal with syzbot reports late at night or on weekends, or have decided to just ignore them since the signal is drowned out by the noise. It was **not** intended for users to disable that feature on production systems.
At some point, in the future, the following thing needs to happen to before blocking writes to the block device can be enabled for real:
*) E2fprogs's tune2fs program needs to be taught to use
EXT4_IOC_GET_TUNE_SB_PARAM and EXT4_IOC_SET_TUNE_SB_PARAM ioctls so that the changes that are allowed to be made while the file system is mounted are done via this ioctls.
*) The kernel is enhanced so that write access to block device with a
mounted file system can be blocked on a per "struct super", so the file system can block access either on per file system basis, or on a per mount basis based on a mount option.
*) We can only enable blocking block device writes to mounted file
systems when we are use that users have both a kernel and e2fsprogs with support of EXT4_IOC_[SG]ET_TUNE_SB_PARAM.
Also note that at the moment, disabling block device writes of file systems is at this point security theatre which is only rivaled by the metal detectors in the airport operating by the United States Transport Security Agency. That's because !CONFIG_BLK_DEV_WRITE_MOUNTED can be trivially bypassed by using the loop device.
Cheers,
- Ted
Quoted 22 lines
resize/main.c +1
-4@@ -256,7 +256,7 @@ int main (int argc, char ** argv)int force_min_size =0 ;int print_min_size =0 ;int fd, ret; -int open_flags =O_RDWR ; +int open_flags =O_RDONLY ;blk64_t new_size =0 ;blk64_t max_size =0 ;blk64_t min_size =0 ;@@ -364,9 +364,6 @@ int main (int argc, char ** argv) len =2 * len; } -if (print_min_size) - open_flags =O_RDONLY ; - fd =ext2fs_open_file (device_name, open_flags,0 );if (fd <0 ) { com_err("open", errno, _("while opening %s"),