Skip to content

Commit 009a2ba

Browse files
LATENTBOUNCEbrauner
authored andcommitted
Fix a drop_nlink warning in minix_rename
Syzbot found a drop_nlink warning that is triggered by an easy to detect nlink corruption. This patch adds sanity checks to minix_unlink and minix_rename to prevent the warning and instead return EFSCORRUPTED to the caller. The changes were tested using the syzbot reproducer as well as local testing. Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl> Link: https://patch.msgid.link/20251104143005.3283980-4-jkoolstra@xs4all.nl Reviewed-by: Jan Kara <jack@suse.cz> Reported-by: syzbot+a65e824272c5f741247d@syzkaller.appspotmail.com Closes: https://syzbot.org/bug?extid=a65e824272c5f741247d Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent d3e0e86 commit 009a2ba

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

fs/minix/namei.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ static int minix_unlink(struct inode * dir, struct dentry *dentry)
145145
struct minix_dir_entry * de;
146146
int err;
147147

148+
if (inode->i_nlink == 0) {
149+
minix_error_inode(inode, "inode has corrupted nlink");
150+
return -EFSCORRUPTED;
151+
}
152+
148153
de = minix_find_entry(dentry, &folio);
149154
if (!de)
150155
return -ENOENT;
@@ -217,6 +222,17 @@ static int minix_rename(struct mnt_idmap *idmap,
217222
if (dir_de && !minix_empty_dir(new_inode))
218223
goto out_dir;
219224

225+
err = -EFSCORRUPTED;
226+
if (new_inode->i_nlink == 0 || (dir_de && new_inode->i_nlink != 2)) {
227+
minix_error_inode(new_inode, "inode has corrupted nlink");
228+
goto out_dir;
229+
}
230+
231+
if (dir_de && old_dir->i_nlink <= 2) {
232+
minix_error_inode(old_dir, "inode has corrupted nlink");
233+
goto out_dir;
234+
}
235+
220236
err = -ENOENT;
221237
new_de = minix_find_entry(new_dentry, &new_folio);
222238
if (!new_de)

0 commit comments

Comments
 (0)