Skip to contentSkip to conversation

fs: minix: Fix handling of corrupted directories

PATCH Superseded Andrey Kriulin 2 participants 2 messages May 14, 2025 Stable branch

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 fs: minix: Fix handling of corrupted directories

If the directory is corrupted and the number of nlinks is less than 2 (valid nlinks have at least 2), then when the directory is deleted, the minix_rmdir will try to reduce the nlinks(unsigned int) to a negative value.

Make nlinks validity check for directory in minix_lookup.

---
v2: Move nlinks validaty check to V[12]_minix_iget() per Jan Kara <[email protected]> request. Change return error code to EUCLEAN. Don't block directory in r/o mode per Al Viro <[email protected]> request.

 fs/minix/inode.c | 16 ++++++++++++++++
 fs/minix/namei.c |  7 +------
 2 files changed, 17 insertions(+), 6 deletions(-)
fs/minix/inode.c +16 -0
index f007e389d5d2..d815397b8b0d 100644
@@ -517,6 +517,14 @@ static struct inode *V1_minix_iget(struct inode *inode)
 		iget_failed(inode);
 		return ERR_PTR(-ESTALE);
 	}
+	if (S_ISDIR(raw_inode->i_mode) && raw_inode->i_nlinks < 2) {
+		printk("MINIX-fs: inode directory with corrupted number of links");
+		if (!sb_rdonly(inode->i_sb)) {
+			brelse(bh);
+			iget_failed(inode);
+			return ERR_PTR(-EUCLEAN);
+		}
+	}
 	inode->i_mode = raw_inode->i_mode;
 	i_uid_write(inode, raw_inode->i_uid);
 	i_gid_write(inode, raw_inode->i_gid);
@@ -555,6 +563,14 @@ static struct inode *V2_minix_iget(struct inode *inode)
 		iget_failed(inode);
 		return ERR_PTR(-ESTALE);
 	}
+	if (S_ISDIR(raw_inode->i_mode) && raw_inode->i_nlinks < 2) {
+		printk("MINIX-fs: inode directory with corrupted number of links");
+		if (!sb_rdonly(inode->i_sb)) {
+			brelse(bh);
+			iget_failed(inode);
+			return ERR_PTR(-EUCLEAN);
+		}
+	}
 	inode->i_mode = raw_inode->i_mode;
 	i_uid_write(inode, raw_inode->i_uid);
 	i_gid_write(inode, raw_inode->i_gid);
fs/minix/namei.c +1 -6
index 5717a56fa01a..8938536d8d3c 100644
@@ -28,13 +28,8 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, un
 		return ERR_PTR(-ENAMETOOLONG);
 
 	ino = minix_inode_by_name(dentry);
-	if (ino) {
+	if (ino)
 		inode = minix_iget(dir->i_sb, ino);
-		if (S_ISDIR(inode->i_mode) && inode->i_nlink < 2) {
-			iput(inode);
-			return ERR_PTR(-EIO);
-		}
-	}
 	return d_splice_alias(inode, dentry);
 }
 
Signature · 1 line
2.47.2
#1 lore raw
FYI: kernel test robot notices the stable kernel rule is not satisfied.

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH v2 2/2] fs: minix: Fix handling of corrupted directories

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki