Skip to content

Commit 19134a1

Browse files
haruki3hhhjankara
authored andcommitted
ext2: avoid drop_nlink() during unlink of zero-nlink inode in ext2_unlink()
ext2_unlink() calls inode_dec_link_count() unconditionally, which invokes drop_nlink(). If the inode was loaded from a corrupted disk image with i_links_count == 0, drop_nlink() triggers WARN_ON(inode->i_nlink == 0) Follow the ext4 pattern from __ext4_unlink(): check i_nlink before decrementing. If already zero, skip the decrement. Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu> Link: https://patch.msgid.link/20260211022052.973114-1-n7l8m4@u.northwestern.edu Signed-off-by: Jan Kara <jack@suse.cz>
1 parent ad0e966 commit 19134a1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

fs/ext2/namei.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ static int ext2_unlink(struct inode *dir, struct dentry *dentry)
291291
goto out;
292292

293293
inode_set_ctime_to_ts(inode, inode_get_ctime(dir));
294-
inode_dec_link_count(inode);
294+
295+
if (inode->i_nlink)
296+
inode_dec_link_count(inode);
297+
295298
err = 0;
296299
out:
297300
return err;

0 commit comments

Comments
 (0)