[PATCH] Squashfs: return -EINVAL when directory size check fails

From: Xiaolei Wang

Date: Sun Nov 15 2026 - 22:51:33 EST


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: syzbot+7b1d0ea11475e857d063@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=7b1d0ea11475e857d063
Fixes: 5213b0a08263 ("Squashfs: fix variables in directory code and add more sanity checks")
Signed-off-by: Xiaolei Wang <wangxiaolei01@xxxxxxxxxxx>
---
fs/squashfs/inode.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c
index 5404d7ba6fc0..4cf8a41b5859 100644
--- a/fs/squashfs/inode.c
+++ b/fs/squashfs/inode.c
@@ -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));
--
2.34.1