Skip to contentSkip to conversation

Fix a drop_nlink warning in minix_rmdir

PATCH In review Jori Koolstra 2 participants 4 messages Nov 2, 2025 – Nov 4, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 fs/minix/minix.h |  2 ++
 fs/minix/namei.c | 26 ++++++++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)
fs/minix/minix.h +2 -0
index d54273c3c9ff..ce62cb61186d 100644
@@ -168,4 +168,6 @@ static inline int minix_test_bit(int nr, const void *vaddr)
 
 #endif
 
+#define EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
+
 #endif /* FS_MINIX_H */
fs/minix/namei.c +18 -8
index 8938536d8d3c..a8d5a7e22b7b 100644
@@ -161,15 +161,25 @@ 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) {
+		printk(KERN_CRIT "minix-fs error: directory 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;
 }
 
Signature · 1 line
2.51.1.dirty
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jori Koolstra

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.

Looks good, just one nit below. With that fixed feel free to add:

Quoted 11 lines
fs/minix/namei.c +0 -3
index 8938536d8d3c..a8d5a7e22b7b 100644
@@ -161,15 +161,25 @@ 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)) {

fs/minix/namei.c static int minix_unlink(struct inode * dir, struct dentry *dentry) · line 168

Quoted 10 lines
fs/minix/namei.c +5 -5
-		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) {
+		printk(KERN_CRIT "minix-fs error: directory inode has "
+		       "corrupted nlink");

We usually print inode number (dir->i_ino) with such errors in minix.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw

Hello Jan,

Quoted 5 lines

Looks good, just one nit below. With that fixed feel free to add:

Will do. Question: I have fixed another syzbot bug report in minix_rename/unlink and posted the patch. I figured that because they target different syzbot reports, they should be separate patches. However, I forgot to add the EFSCORRUPTED define in that patch (but did include it in the #syz test). What is the best way to rectify that and add your suggestion to this patch? Or should it be a single patch, or a series? I want to cause as little work as possible for you and other maintainers.

Thanks,
Jori.

#3 lore raw

Hello Jori!

Quoted 11 lines · Jori Koolstra
Quoted 3 lines

Looks good, just one nit below. With that fixed feel free to add:

Will do. Question: I have fixed another syzbot bug report in minix_rename/unlink and posted the patch. I figured that because they target different syzbot reports, they should be separate patches. However, I forgot to add the EFSCORRUPTED define in that patch (but did include it in the #syz test). What is the best way to rectify that and add your suggestion to this patch? Or should it be a single patch, or a series? I want to cause as little work as possible for you and other maintainers.

The most natural would be to submit these two patches in a single series since they are actually related.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR