mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to reject inline_data inode which has blocks
@ 2026-11-22 15:36 Hengyu Liang
  2026-12-01  8:15 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Hengyu Liang @ 2026-11-22 15:36 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: Taerang Kim, linux-f2fs-devel, linux-kernel, stable

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/f

Before 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.

Fixes: c240c87bcd44 ("f2fs: fix to do sanity check on blocks for inline_data inode")
Cc: stable@vger.kernel.org
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
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/20260317152838.26664-1-kth5965@gmail.com/

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(-)

diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 032c1cf8c615..2c50a72580af 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -54,7 +54,7 @@ bool f2fs_sanity_check_inline_data(struct inode *inode, struct f2fs_cached_block
 		return false;
 
 	if (inode_has_blocks(inode, ientry))
-		return false;
+		return true;
 
 	if (!support_inline_data(inode))
 		return true;

base-commit: b61a029304bb5531312ebc133b2a895d14dc3fee
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] f2fs: fix to reject inline_data inode which has blocks
  2026-11-22 15:36 [PATCH] f2fs: fix to reject inline_data inode which has blocks Hengyu Liang
@ 2026-12-01  8:15 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Hengyu Liang, Jaegeuk Kim
  Cc: chao, Taerang Kim, linux-f2fs-devel, linux-kernel, stable

On 11/22/26 23:36, Hengyu Liang wrote:
> 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/f
> 
> Before 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.
> 
> Fixes: c240c87bcd44 ("f2fs: fix to do sanity check on blocks for inline_data inode")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01  8:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 15:36 [PATCH] f2fs: fix to reject inline_data inode which has blocks Hengyu Liang
2026-12-01  8:15 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®