[PATCH 2/2] squashfs: return -EIO on out-of-bounds directory entry in lookup
From: Aibing Chen
Date: Sat Nov 14 2026 - 09:51:49 EST
The three squashfs_dir_space() bounds checks added to
squashfs_lookup() by commit 5213b0a08263 ("Squashfs: fix variables in
directory code and add more sanity checks") jump to read_failure
without setting err. err then holds the positive number of bytes
read by the last successful squashfs_read_metadata() (8 for a
directory entry), and squashfs_lookup() returns ERR_PTR(err) with a
positive value, which IS_ERR() does not catch. The VFS dereferences
the bogus pointer and crashes:
general protection fault in lookup_open ...
RIP: lookup_open+0x890/0x16e0 fs/namei.c:4648
...
squashfs_lookup fs/squashfs/namei.c:250 [inline]
...
The squashfs_dir_space() checks validate on-disk directory content,
so jump to data_error (which sets err = -EIO), matching the
neighbouring content validation checks.
Reported-by: syzbot+0b7a8fb8279a59e8a188@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=0b7a8fb8279a59e8a188
Fixes: 5213b0a08263 ("Squashfs: fix variables in directory code and add more sanity checks")
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
fs/squashfs/namei.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c
index 5f8decee2..5dc21ddaf 100644
--- a/fs/squashfs/namei.c
+++ b/fs/squashfs/namei.c
@@ -203,7 +203,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry,
* Read directory header.
*/
if (!squashfs_dir_space(dir, length, sizeof(dirh)))
- goto read_failure;
+ goto data_error;
err = squashfs_read_metadata(dir->i_sb, &dirh, &block,
&offset, sizeof(dirh));
@@ -222,7 +222,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry,
* Read directory entry.
*/
if (!squashfs_dir_space(dir, length, sizeof(*dire)))
- goto read_failure;
+ goto data_error;
err = squashfs_read_metadata(dir->i_sb, dire, &block,
&offset, sizeof(*dire));
@@ -237,7 +237,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry,
goto data_error;
if (!squashfs_dir_space(dir, length, size))
- goto read_failure;
+ goto data_error;
err = squashfs_read_metadata(dir->i_sb, dire->name,
&block, &offset, size);
--
2.50.1.windows.1