Skip to contentSkip to conversation

squashfs: set an error code on the directory header bounds check in lookup

PATCH New William Chuang 1 participant 1 message Nov 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 squashfs: set an error code on the directory header bounds check in lookup

The squashfs_dir_space() check before the directory header read in squashfs_lookup() jumps to read_failure without setting err. The two checks before the entry and name reads were given an error code by squashfs-fix-variables-in-directory-code-and-add-more-sanity-checks-fix, but this one was missed.

On this path err is either the positive byte count of an earlier successful squashfs_read_metadata() call (12 after a directory header), or uninitialised when the check fails on the first iteration (for a directory whose size is too small to hold a header). squashfs_lookup() then returns ERR_PTR(err) with a value that IS_ERR() does not catch, and the VFS dereferences it.

A model check (CBMC) of squashfs_lookup() as it stands in mm-nonmm-unstable produces both cases: a 15-byte directory gives ERR_PTR(12), and a 9-byte directory gives ERR_PTR(<uninitialised>). With this change, the same check proves that every return value is NULL, a dentry, or ERR_PTR(-errno), for every directory size.

The header check validates on-disk directory content, so jump to data_error (-EIO) like the neighbouring dir_count check. Aibing Chen posted the same hunk as part of "[PATCH 2/2] squashfs: return -EIO on out-of-bounds directory entry in lookup" on 2026-11-14.

Fixes 5213b0a08263 ("Squashfs: fix variables in directory code and add more sanity checks")

---
Notes for reviewers (not part of the commit):

- This is the third squashfs_dir_space() path; Dan noted two. The fix goes on top of squashfs-fix-variables-in-directory-code-and-add-more- sanity-checks-fix and can simply be folded into it. If -ENOSPC is preferred for consistency with that fix, I'm happy to respin.
- squashfs_read_inode() has the same problem: the two new "i_size < 3" checks reach failed_read with err = 32 or 40. That is fixed by Aibing Chen's "[PATCH 1/2] squashfs: return -EINVAL on invalid directory inode size" (2026-11-14), which is still needed.
- The model-checking harnesses and outputs are available on request.

 fs/squashfs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/squashfs/namei.c +1 -1
index dc63920..1945e5d 100644
@@ -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));
Signature · 1 line
2.43.0