2023-08-02 09:12:51

by zhanchengbin

[permalink] [raw]
Subject: [RFC PATCH 0/2] ext4: Fix the conflict between modifying the superblock in user mode and kernel mode

Tune2fs does not recognize writes to filesystems in another namespace. Two
simultaneous write operations on a block will lead to file system
inconsistency, because there is no lock protection between userland and
kernelland.

The operation is as follows:
first terminal second terminal
mkfs.ext4 /dev/sdb;
mount /dev/sdb /test-sdb;
dd if=/dev/zero of=/test-sdb/test1 bs=1M count=100;
unshare -m;
umount;
gdb tune2fs;
b io_channel_write_byte
r -e remount-ro /dev/sdb
c(Write a byte of old data into the cache)
exit;
(gdb finish)
tune2fs -l /dev/sdb;
tune2fs 1.46.4 (18-Aug-2021)
tune2fs: Superblock checksum does not match superblock while trying to
open /dev/sdb
Couldn't find valid filesystem superblock.

Link: https://lore.kernel.org/linux-ext4/[email protected]/

After discussing with Tytso, I decided to use ioctl to solve the above
problems. These patches are an example I wrote to complete the modification
of the s_errors variable in the super block.

Finally, if you have any good ideas, welcome to communicate with me by
email.

zhanchengbin (2):
ext4: ioctl adds a framework for modifying superblock parameters
ext4: ioctl add EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS

fs/ext4/ext4.h | 12 +++
fs/ext4/ioctl.c | 149 ++++++++++++++++++++++++++++++++++++++
include/uapi/linux/ext4.h | 28 +++++++
3 files changed, 189 insertions(+)

--
2.31.1