]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Fix a drop_nlink warning in minix_rmdir
authorJori Koolstra <jkoolstra@xs4all.nl>
Tue, 4 Nov 2025 14:30:04 +0000 (15:30 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 5 Nov 2025 12:45:21 +0000 (13:45 +0100)
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>
fs/minix/namei.c

index 8938536d8d3cf65c7e57f88f1819689365951fea..68d2dd75b97fb6bc773b08e9ba0e647cad299c81 100644 (file)
@@ -161,15 +161,24 @@ static int minix_unlink(struct inode * dir, struct dentry *dentry)
 static int minix_rmdir(struct inode * dir, struct dentry *dentry)
 {
        struct inode * inode = d_inode(dentry);
-       int err = -ENOTEMPTY;
-
-       if (minix_empty_dir(inode)) {
-               err = minix_unlink(dir, dentry);
-               if (!err) {
-                       inode_dec_link_count(dir);
-                       inode_dec_link_count(inode);
-               }
+       int err = -EFSCORRUPTED;
+
+       if (dir->i_nlink <= 2) {
+               minix_error_inode(dir, "inode has corrupted nlink");
+               goto out;
+       }
+
+       err = -ENOTEMPTY;
+       if (!minix_empty_dir(inode))
+               goto out;
+
+       err = minix_unlink(dir, dentry);
+       if (!err) {
+               inode_dec_link_count(dir);
+               inode_dec_link_count(inode);
        }
+
+out:
        return err;
 }