From: Vasiliy Kovalev <kovalev@altlinux.org>
To: Jan Kara <jack@suse.com>, Andrew Morton <akpm@osdl.org>,
Alexey Dobriyan <adobriyan@gmail.com>,
linux-ext4@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
kovalev@altlinux.org
Subject: [PATCH 2/2] ext2: guard against zero i_nlink on new_inode in ext2_rename()
Date: Thu, 2 Apr 2026 01:08:37 +0300 [thread overview]
Message-ID: <20260401220837.2424925-3-kovalev@altlinux.org> (raw)
In-Reply-To: <20260401220837.2424925-1-kovalev@altlinux.org>
A crafted ext2 image can provide a target inode with i_links_count == 0
on disk. When rename() resolves to an existing target, ext2_rename()
calls drop_nlink(new_inode) for the directory case and
inode_dec_link_count(new_inode) unconditionally. Both reach
drop_nlink(), which triggers WARN_ON:
WARNING: CPU: 0 PID: 646 at fs/inode.c:336 drop_nlink+0xad/0xd0 fs/inode.c:336
CPU: 0 UID: 0 PID: 646 Comm: syz.0.17 Not tainted 6.12.77+ #1
Call Trace:
<TASK>
inode_dec_link_count include/linux/fs.h:2518 [inline]
ext2_rename+0x35e/0x850 fs/ext2/namei.c:374
vfs_rename+0xf2f/0x2060 fs/namei.c:5021
do_renameat2+0xbe2/0xd50 fs/namei.c:5178
__do_sys_rename fs/namei.c:5225 [inline]
__se_sys_rename fs/namei.c:5223 [inline]
__x64_sys_rename+0x7e/0xa0 fs/namei.c:5223
do_syscall_x64 arch/x86/entry/common.c:47 [inline]
do_syscall_64+0xf5/0x220 arch/x86/entry/common.c:78
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
No disk state has been modified at this point in the function, so
return -EFSCORRUPTED after reporting the corruption via ext2_error().
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Cc: stable@vger.kernel.org
Fixes: 9a53c3a783c2 ("[PATCH] r/o bind mounts: unlink: monitor i_nlink")
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
---
fs/ext2/namei.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index ea49e8f2b292..419e844f2e54 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -334,6 +334,13 @@ static int ext2_rename (struct mnt_idmap * idmap,
bool old_is_dir = S_ISDIR(old_inode->i_mode);
int err;
+ if (new_inode && new_inode->i_nlink == 0) {
+ ext2_error(old_dir->i_sb, __func__,
+ "target inode %lu has zero i_nlink, filesystem may be corrupt",
+ new_inode->i_ino);
+ return -EFSCORRUPTED;
+ }
+
if (flags & ~RENAME_NOREPLACE)
return -EINVAL;
--
2.50.1
next prev parent reply other threads:[~2026-04-01 22:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 22:08 [PATCH 0/2] ext2: fix WARN_ON in drop_nlink() triggered by corrupt images Vasiliy Kovalev
2026-04-01 22:08 ` [PATCH 1/2] ext2: validate i_nlink before decrement in ext2_unlink() Vasiliy Kovalev
2026-04-01 22:08 ` Vasiliy Kovalev [this message]
2026-04-04 15:27 ` [PATCH 0/2] ext2: fix WARN_ON in drop_nlink() triggered by corrupt images Vasiliy Kovalev
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=20260401220837.2424925-3-kovalev@altlinux.org \
--to=kovalev@altlinux.org \
--cc=adobriyan@gmail.com \
--cc=akpm@osdl.org \
--cc=jack@suse.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
/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