lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <68f89f53.050a0220.346f24.003a.GAE@google.com>
Date: Wed, 22 Oct 2025 02:09:39 -0700
From: syzbot <syzbot+632cf32276a9a564188d@...kaller.appspotmail.com>
To: linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com
Subject: Forwarded: [PATCH] f2fs: add validation for directory depth in sanity_check_inode

For archival purposes, forwarding an incoming command email to
linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com.

***

Subject: [PATCH] f2fs: add validation for directory depth in sanity_check_inode
Author: kartikey406@...il.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@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=632cf32276a9a564188d
Signed-off-by: Deepanshu Kartikey <kartikey406@...il.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ