Skip to contentSkip to conversation

Squashfs: return -EINVAL when directory size check fails

PATCH New Xiaolei Wang 1 participant 1 message Nov 16 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Squashfs: return -EINVAL when directory size check fails

The directory size checks added by commit 5213b0a08263 ("Squashfs:
fix variables in directory code and add more sanity checks") jump to failed_read without setting err. err still holds the positive byte count returned by squashfs_read_metadata(), so squashfs_read_inode() returns 32 for SQUASHFS_DIR_TYPE and 40 for SQUASHFS_LDIR_TYPE instead of an errno.

Note this only affects linux-next: the commit above is not in mainline yet.

squashfs_fill_super() then fails before sb->s_root is set. vfs_get_tree() only treats negative returns as errors, so it reaches the "didn't set fc->root" BUG() in fs/super.c.

Set err to -EINVAL at both check sites so a corrupt directory inode is rejected with a proper errno.

SQUASHFS error: Unable to read inode 0x11f
Filesystem squashfs get_tree() didn't set fc->root, returned 40 kernel BUG at fs/super.c:2174!

Reported-by [email protected]
Fixes 5213b0a08263 ("Squashfs: fix variables in directory code and add more sanity checks")
---
 fs/squashfs/inode.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/squashfs/inode.c +6 -2
index 5404d7ba6fc0..4cf8a41b5859 100644
@@ -255,8 +255,10 @@ int squashfs_read_inode(struct inode *inode, long long ino)
 
 		/* The directory size must be 3 or larger, as it includes "." and ".." entries */
 		inode->i_size = le16_to_cpu(sqsh_ino->file_size);
-		if (inode->i_size < 3)
+		if (inode->i_size < 3) {
+			err = -EINVAL;
 			goto failed_read;
+		}
 
 		set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
 		inode->i_op = &squashfs_dir_inode_ops;
@@ -284,8 +286,10 @@ int squashfs_read_inode(struct inode *inode, long long ino)
 
 		/* The directory size must be 3 or larger, as it includes "." and ".." entries */
 		inode->i_size = le32_to_cpu(sqsh_ino->file_size);
-		if (inode->i_size < 3)
+		if (inode->i_size < 3) {
+			err = -EINVAL;
 			goto failed_read;
+		}
 
 		xattr_id = le32_to_cpu(sqsh_ino->xattr);
 		set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
Signature · 1 line
2.34.1