From: syzbot <syzbot+632cf32276a9a564188d@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] f2fs: add validation for directory depth in sanity_check_inode
Date: Wed, 22 Oct 2025 02:09:39 -0700 [thread overview]
Message-ID: <68f89f53.050a0220.346f24.003a.GAE@google.com> (raw)
In-Reply-To: <68ed75c7.050a0220.91a22.01ef.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] f2fs: add validation for directory depth in sanity_check_inode
Author: kartikey406@gmail.com
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
F2FS can mount a corrupted filesystem with an invalid directory depth
value (i_current_depth). When this corrupted directory is accessed
during operations like rename, F2FS fails to properly locate and delete
directory entries, leading to inconsistent inode state.
This triggers a warning in drop_nlink() when attempting to decrement
i_nlink from 0, as directory entries persist even after the link count
reaches zero.
Add validation in sanity_check_inode() to reject inodes with
i_current_depth exceeding MAX_DIR_HASH_DEPTH (63). This prevents
mounting corrupted filesystems and avoids subsequent filesystem
inconsistencies.
Reproducer:
1. Mount corrupted F2FS image with i_current_depth = 16842753
2. Perform rename operations on files in the corrupted directory
3. System triggers WARNING in drop_nlink() due to i_nlink underflow
With this fix, the corrupted filesystem is rejected at mount time
with a clear error message.
Reported-by: syzbot+632cf32276a9a564188d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=632cf32276a9a564188d
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/f2fs/inode.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 8c4eafe9ffac..276adfbd5b30 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -294,6 +294,17 @@ static bool sanity_check_inode(struct inode *inode, struct folio *node_folio)
return false;
}
+ /* Validate directory depth */
+ if (S_ISDIR(le16_to_cpu(ri->i_mode))) {
+ unsigned int current_depth = le32_to_cpu(ri->i_current_depth);
+
+ if (current_depth > MAX_DIR_HASH_DEPTH) {
+ f2fs_warn(sbi, "%s: corrupted inode i_ino=%lx has invalid i_current_depth: %u, max: %u, run fsck to fix.",
+ __func__, inode->i_ino, current_depth, MAX_DIR_HASH_DEPTH);
+ return false;
+ }
+ }
+
if (f2fs_has_extra_attr(inode)) {
if (!f2fs_sb_has_extra_attr(sbi)) {
f2fs_warn(sbi, "%s: inode (ino=%lx) is with extra_attr, but extra_attr feature is off",
--
2.43.0
next prev parent reply other threads:[~2025-10-22 9:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 21:57 [syzbot] [f2fs?] WARNING in f2fs_rename2 (2) syzbot
2025-10-22 9:09 ` syzbot [this message]
2025-10-22 16:30 ` Forwarded: [PATCH] f2fs: invalidate dentry cache on failed whiteout creation syzbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68f89f53.050a0220.346f24.003a.GAE@google.com \
--to=syzbot+632cf32276a9a564188d@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®