From nobody Sun May 24 20:33:22 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B60E1A3166 for ; Fri, 22 May 2026 07:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779436410; cv=none; b=a2NYHBNhcRfol15Xm0MmQlD7h/cAK+h6f+wPg1cC9kzNajRIsscVQ9Jw3vYwR9C8vqxfeGjLTEK48MA8BS7vJjmwxRbIEqLa6lU6cAg38c7IWEbwOyO2L9dY5C5ujrRj5JsxVBZc/gppxEY3aD8GpS1z3ieeLzeVIb9Y+B6pjn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779436410; c=relaxed/simple; bh=QkdE6iYHtzrCXK3HB8BjiTxMGJLFV5jd9TEA0FAm6ao=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=N8XsO9Jsl/uMGovCB8fHMkfPrUuavy6voCdfmwzem0+7rpw4BIstchB8jPnHrpF8SqcpzKFlRedKninq5ADh8fXitm1vAoW7M40wVOeQHs57ex4N5hthfln1M9/d1U2qBqpvhapv6cX/jvlCY1DLqCIcnNIw6kSwtEf+ltkUDT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ipftsE9N; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ipftsE9N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA111F000E9; Fri, 22 May 2026 07:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779436409; bh=eSR5TM5dP8VMBQSWB1mR4M0bSsygysctU8QEmKMojsk=; h=From:To:Cc:Subject:Date; b=ipftsE9N14knQvSVxA+Iuv/pFBuMw1ffj2fDpKJWeTjDY66S9GZ9Ilt67rVy+1syD tz8lede4M86TKsbnKp5BdICp+B+hYtuVYKfkOXzfD47W8mIVvQKDQp6oSkbKMzaB3J fC++8SIi8r3YbH3AuHsWKxqV3/mKnZkUrMXfF6/y5wkLLcd40FRSxTetumjvnUrT+o jcbrkg2xE323FyA3yiPYREp85WuFg6yc+wiEk4yYFnncRRiZ9FuMQWprzzDosKpI4Y d5MDZtpjXS53fVVF4ozsFupdVOPcmjKLYvuQMG/vyAXBHR5h+guzWD5CqacrzbPdfP frfvdxuO1zMRA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , stable@kernel.org, syzbot+2488d8d751b27f7ce268@syzkaller.appspotmail.com Subject: [PATCH] f2fs: fix to do sanity check on f2fs_get_node_folio_ra() Date: Fri, 22 May 2026 15:53:29 +0800 Message-Id: <20260522075329.12079-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" kernel BUG at fs/f2fs/file.c:845! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI CPU: 0 UID: 0 PID: 5336 Comm: syz.0.0 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16= .3-2 04/01/2014 RIP: 0010:f2fs_do_truncate_blocks+0x1115/0x1140 fs/f2fs/file.c:845 Code: fc fc 90 0f 0b e8 8b 9d 9a fd 90 0f 0b e8 83 9d 9a fd 48 89 df 48 c7 = c6 60 d1 1a 8c e8 54 f1 fc fc 90 0f 0b e8 6c 9d 9a fd 90 <0f> 0b e8 64 9d 9= a fd 90 0f 0b 90 e9 93 fd ff ff e8 56 9d 9a fd 90 RSP: 0018:ffffc9000e4474c0 EFLAGS: 00010283 RAX: ffffffff842b1d34 RBX: 0000000000000003 RCX: 0000000000100000 RDX: ffffc9000f03a000 RSI: 0000000000035503 RDI: 0000000000035504 RBP: ffffc9000e447608 R08: ffff8880123b0000 R09: 0000000000000002 R10: 00000000fffffffe R11: 0000000000000002 R12: 0000000000000001 R13: 0000000000000000 R14: 1ffff92001c88ea0 R15: 00000000ffff039c FS: 00007f7e02ee36c0(0000) GS:ffff88808c887000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ff0305c4000 CR3: 0000000012d4c000 CR4: 0000000000352ef0 Call Trace: f2fs_truncate_blocks+0x10a/0x300 fs/f2fs/file.c:882 f2fs_truncate+0x471/0x7c0 fs/f2fs/file.c:940 f2fs_evict_inode+0xa3f/0x1ac0 fs/f2fs/inode.c:907 evict+0x61e/0xb10 fs/inode.c:841 f2fs_fill_super+0x5f43/0x78f0 fs/f2fs/super.c:5224 get_tree_bdev_flags+0x431/0x4f0 fs/super.c:1694 vfs_get_tree+0x92/0x2a0 fs/super.c:1754 fc_mount fs/namespace.c:1193 [inline] do_new_mount_fc fs/namespace.c:3758 [inline] do_new_mount+0x341/0xd30 fs/namespace.c:3834 do_mount fs/namespace.c:4167 [inline] __do_sys_mount fs/namespace.c:4383 [inline] __se_sys_mount+0x31d/0x420 fs/namespace.c:4360 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f count =3D ADDRS_PER_PAGE(dn.node_folio, inode); count -=3D dn.ofs_in_node; f2fs_bug_on(sbi, count < 0); The fuzz test will trigger above bug_on in f2fs. The root cause should be: in the corrupted inode, there is a direct node which has the same ino and nid in its footer, so in f2fs_do_truncate_blocks= (), after f2fs_get_dnode_of_data() finds such dnode: 1) ADDRS_PER_PAGE(dn.node_folio, inode) will return 923 2) once dn.ofs_in_node points to addr[923, 1017] Then it will trigger the system panic. Let's introduce NODE_TYPE_NON_IXNODE to indicate current node should not be an inode or xattr node, and then use it in below path to detect inconsistent node chain in inode mapping table: - f2fs_do_truncate_blocks - f2fs_get_dnode_of_data - f2fs_get_node_folio_ra - __get_node_folio - f2fs_sanity_check_node_footer - case NODE_TYPE_NON_IXNODE -> check whether it is inode|xnode Cc: stable@kernel.org Reported-by: syzbot+2488d8d751b27f7ce268@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/69fa3697.170a0220.59368.0018.GAE@google= .com Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 1 + fs/f2fs/node.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fffb516b78f4..f528f9954764 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1593,6 +1593,7 @@ enum node_type { NODE_TYPE_INODE, NODE_TYPE_XATTR, NODE_TYPE_NON_INODE, + NODE_TYPE_NON_IXNODE, /* non inode and xnode */ }; =20 /* a threshold of maximum elapsed time in critical region to print tracepo= int */ diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index cd5a394f6111..38917e4a7319 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1548,6 +1548,10 @@ int f2fs_sanity_check_node_footer(struct f2fs_sb_inf= o *sbi, if (is_inode) goto out_err; break; + case NODE_TYPE_NON_IXNODE: + if (is_inode || is_xnode) + goto out_err; + break; default: break; } @@ -1643,7 +1647,7 @@ static struct folio *f2fs_get_node_folio_ra(struct fo= lio *parent, int start) struct f2fs_sb_info *sbi =3D F2FS_F_SB(parent); nid_t nid =3D get_nid(parent, start, false); =20 - return __get_node_folio(sbi, nid, parent, start, NODE_TYPE_REGULAR); + return __get_node_folio(sbi, nid, parent, start, NODE_TYPE_NON_IXNODE); } =20 static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino) --=20 2.40.1