Skip to content

Commit d3e0e86

Browse files
LATENTBOUNCEbrauner
authored andcommitted
Fix a drop_nlink warning in minix_rmdir
Syzbot found a drop_nlink warning that is triggered by an easy to detect nlink corruption of a directory. This patch adds a sanity check to minix_rmdir 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-3-jkoolstra@xs4all.nl Reviewed-by: Jan Kara <jack@suse.cz> Reported-by: syzbot+4e49728ec1cbaf3b91d2@syzkaller.appspotmail.com Closes: https://syzbot.org/bug?extid=4e49728ec1cbaf3b91d2 Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 21215ce commit d3e0e86

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

fs/minix/namei.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,24 @@ static int minix_unlink(struct inode * dir, struct dentry *dentry)
161161
static int minix_rmdir(struct inode * dir, struct dentry *dentry)
162162
{
163163
struct inode * inode = d_inode(dentry);
164-
int err = -ENOTEMPTY;
165-
166-
if (minix_empty_dir(inode)) {
167-
err = minix_unlink(dir, dentry);
168-
if (!err) {
169-
inode_dec_link_count(dir);
170-
inode_dec_link_count(inode);
171-
}
164+
int err = -EFSCORRUPTED;
165+
166+
if (dir->i_nlink <= 2) {
167+
minix_error_inode(dir, "inode has corrupted nlink");
168+
goto out;
169+
}
170+
171+
err = -ENOTEMPTY;
172+
if (!minix_empty_dir(inode))
173+
goto out;
174+
175+
err = minix_unlink(dir, dentry);
176+
if (!err) {
177+
inode_dec_link_count(dir);
178+
inode_dec_link_count(inode);
172179
}
180+
181+
out:
173182
return err;
174183
}
175184

0 commit comments

Comments
 (0)