Re: [PATCH v2] f2fs: verify inode data-block ownership at mount
From: Wang Haoran
Date: Thu Nov 19 2026 - 06:37:38 EST
Hi, thanks for the review.
I tested whether fsck.f2fs already catches this corruption, and it does.
On a locally built image (mkfs.f2fs, two regular files, then rewriting one
inode's i_addr so its direct pointers alias the other file's data blocks),
fsck.f2fs 1.16.0 reports:
[ASSERT] (is_valid_ssa_data_blk: 326) --> Invalid data seg summary
[ASSERT] (fsck_chk_data_blk:1869) --> summary data block is not
valid. [0x4]
[ASSERT] (fsck_chk_inode_blk:1042) --> ino: 0x4 has wrong ext:
[pgofs:0, blk:6674, len:18]
[ASSERT] (fsck_chk_inode_blk:1049) --> ino: 0x4 has i_blocks:
00000013, but has 3 blocks
[FSCK] SIT valid block bitmap checking [Fail]
[FSCK] valid_block_count matching with CP [Fail]
[FSCK] other corrupted bugs [Fail]
So the detection itself is already covered in userspace.
The one gap is that fsck.f2fs is an explicit, userspace step: it runs from
the initramfs/fstab path or by hand, and is not invoked for loop-mounted
images or auto-mounted removable media. A forged image that is mounted
directly therefore passes mount without any check.
Would it make sense to add a mount option (e.g. -o check_ownership) that
runs the same NAT-driven ownership scan, but only when requested? That
keeps the default boot path unchanged, while allowing the check to be
written into mount policy for untrusted or removable media. If that
sounds reasonable I'm happy to rework the patch in that direction.
Thanks,
Haoran
Chao Yu <chao@xxxxxxxxxx> 于2026年11月11日周三 15:14写道:
>
> Hi Haoran,
>
> Thanks for the contribution.
>
> On 11/9/26 17:16, Haoran Wang wrote:
> > At mount time, walk the NAT to enumerate live inode blocks and claim the
> > direct data blocks referenced by each regular inode's i_addr region in a
> > bitmap. If two inodes claim the same data block, fail the mount with
> > -EFSCORRUPTED, since at least one of them is forged or corrupted.
>
> It seems quite heavy to load all valid nodes for verification whenever mount(),
> it may slow down bootup time of filesystem significantly.
>
> If storage device in special environment is not reliable, what do you think of
> running fsck.f2fs to do a full check before mount()?
>
> Thanks,
>