f2fs: fix to reject inline_data inode which has blocks
Subsystems (2)
PATCH 1/1 f2fs: fix to reject inline_data inode which has blocks
Commit c240c87bcd44 ("f2fs: fix to do sanity check on blocks for inline_data inode") made f2fs_sanity_check_inline_data() return false, i.e. "sane", as soon as an inline_data inode has blocks or node ids.
However, the function returns true for a corrupted inode, and that commit meant to detect exactly this state. The early return also skips the older checks that reject inline_data on a directory and on a compressed, encrypted or verity file. As of now, such an inode on a corrupted image is loaded, and setting this one bit in i_inline of an inode is enough for the following:
- unlink() of a small compressed file that owns one data block hits BUG_ON() in clear_inode(). With panic_on_oops=1 the machine panics. Otherwise the task is killed, and the file system can no longer be unmounted (EBUSY).
- unlink() of a larger compressed file succeeds, but the orphan inode cannot be evicted, and the next mount fails with EIO until fsck.f2fs repairs the image.
- A directory lists only 70 of its 300 entries, yet rmdir removes it once those 70 are deleted, and fsck.f2fs then finds the other 230 inodes unreachable.
The issue can be reproduced with:
mkfs.f2fs -q -f -O extra_attr,compression /dev/vda
mount -t f2fs -o compress_algorithm=lz4 /dev/vda /mnt
touch /mnt/f; chattr +c /mnt/f; echo hello > /mnt/f; sync
ino=$(ls -i /mnt/f | awk '{print $1}'); umount /mnt
blk=$(dump.f2fs -d 1 -i $ino /dev/vda |
sed -n 's/.*nat_entry.block_addr *\[0x\(.*\)\]/\1/p')
# i_inline 0x21 -> 0x23 (F2FS_INLINE_DATA)
printf '\043' | dd of=/dev/vda bs=1 seek=$((0x$blk * 4096 + 3)) \
conv=notrunc
mount -t f2fs /dev/vda /mnt; rm /mnt/fBefore that commit, the result is:
rm: can't stat '/mnt/f': Structure needs cleaning
After it, the result is:
kernel BUG at fs/inode.c:776!
With this patch, the result is the same as before that commit.
This patch will make the check return true for an inline_data inode which has blocks, as the message of that commit describes.
---
I found this while comparing the behavior of different kernel versions. I used an LLM to analyze the problem and to draft the patch and this message, and I analyzed the result myself.
I noticed afterwards that Taerang Kim pointed out the same early return in this thread:
https://lore.kernel.org/linux-f2fs-devel/[email protected]/
Tested on f2fs dev (b61a029304bb) with KASAN and lockdep: the reproducer above, the same file with F2FS_DATA_EXIST also set, a 5000-byte compressed file, and a directory with the flag and 300 entries now fail with -EUCLEAN at iget, without BUG, lost entries or a failed mount. On healthy images made by v6.8, v6.18, dev with and without this patch, and sload.f2fs (default; flexible inline xattr + compression; noinline_data; noinline_xattr; sizes around MAX_INLINE_DATA, conversion by append, truncate, mmap, O_DIRECT, fallocate and atomic write, symlinks, xattr node blocks, compressed files, roll-forward recovery after F2FS_IOC_SHUTDOWN), every file reads back unchanged and fsck.f2fs reports no error. The f2fs/*
and the generic shutdown/log/metadata quick tests of fstests that can run here give the same results with and without the patch.
fs/f2fs/inline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/inline.c +1 -1
@@ -54,7 +54,7 @@ bool f2fs_sanity_check_inline_data(struct inode *inode, struct f2fs_cached_blockreturn false;if (inode_has_blocks (inode, ientry)) -return false; +return true;if (!support_inline_data (inode))return true;
base-commit: b61a029304bb5531312ebc133b2a895d14dc3fee
Signature · 1 line
2.53.0
Quoted 43 lines · Hengyu Liang
Commit
c240c87bcd44("f2fs: fix to do sanity check on blocks forinline_datainode") madef2fs_sanity_check_inline_data()return false, i.e. "sane", as soon as aninline_datainode has blocks or node ids.However, the function returns true for a corrupted inode, and that commit meant to detect exactly this state. The early return also skips the older checks that reject
inline_dataon a directory and on a compressed, encrypted or verity file. As of now, such an inode on a corrupted image is loaded, and setting this one bit ini_inlineof an inode is enough for the following:-
unlink()of a small compressed file that owns one data block hitsBUG_ON()inclear_inode(). With panic_on_oops=1 the machine panics. Otherwise the task is killed, and the file system can no longer be unmounted (EBUSY).
-unlink()of a larger compressed file succeeds, but the orphan inode cannot be evicted, and the next mount fails with EIO until fsck.f2fs repairs the image.
- A directory lists only 70 of its 300 entries, yet rmdir removes it once those 70 are deleted, and fsck.f2fs then finds the other 230 inodes unreachable.The issue can be reproduced with:
mkfs.f2fs -q -f -O extra_attr,compression /dev/vda mount -t f2fs -o compress_algorithm=lz4 /dev/vda /mnt touch /mnt/f; chattr +c /mnt/f; echo hello > /mnt/f; sync ino=$(ls -i /mnt/f | awk '{print $1}'); umount /mnt blk=$(dump.f2fs -d 1 -i $ino /dev/vda | sed -n 's/.*nat_entry.block_addr *\[0x\(.*\)\]/\1/p') # i_inline 0x21 -> 0x23 (F2FS_INLINE_DATA) printf '\043' | dd of=/dev/vda bs=1 seek=$((0x$blk * 4096 + 3)) \ conv=notrunc mount -t f2fs /dev/vda /mnt; rm /mnt/fBefore that commit, the result is:
rm: can't stat '
/mnt/f': Structure needs cleaningAfter it, the result is:
kernel BUG at
fs/inode.c:776!
Quoted 8 lines
With this patch, the result is the same as before that commit.
This patch will make the check return true for an
inline_datainode which has blocks, as the message of that commit describes.Fixes c240c87bcd44 ("f2fs: fix to do sanity check on blocks for inline_data inode")Signed-off-by Hengyu Liang <[email protected]>
Thanks,
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 4 lines · On Sun, 22 Nov 2026 10:36:36 -0500 you wrote:
Commit
c240c87bcd44("f2fs: fix to do sanity check on blocks forinline_datainode") madef2fs_sanity_check_inline_data()return false, i.e. "sane", as soon as aninline_datainode has blocks or node ids.
Quoted 8 lines
However, the function returns true for a corrupted inode, and that commit meant to detect exactly this state. The early return also skips the older checks that reject
inline_dataon a directory and on a compressed, encrypted or verity file. As of now, such an inode on a corrupted image is loaded, and setting this one bit ini_inlineof an inode is enough for the following:[...]
Here is the summary with links:
- [f2fs-dev] f2fs: fix to reject inline_data inode which has blocks
https://git.kernel.org/jaegeuk/f2fs/c/ba463915425f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html