mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH 1/2] squashfs: return -EINVAL on invalid directory inode size
@ 2026-11-17  0:54 William Chuang
  0 siblings, 0 replies; 2+ messages in thread
From: William Chuang @ 2026-11-17  0:54 UTC (permalink / raw)
  To: Aibing Chen
  Cc: Phillip Lougher, Andrew Morton, wangxiaolei01, linux-fsdevel,
	linux-kernel, syzbot+5d7ba5f6127ed887f459,
	syzbot+7b1d0ea11475e857d063, syzbot+d8a69701a6e796ad5d3e

Hi Aibing,

Two more open syzbot reports on linux-next 84abb955b101 have the same
root cause as this patch: the two new "i_size < 3" checks in
squashfs_read_inode() reach failed_read with err still holding the
positive byte count of the inode read (32 or 40).

  kernel BUG in vfs_get_tree (3)
  https://syzkaller.appspot.com/bug?extid=7b1d0ea11475e857d063
  (mount: get_tree() returns 40 and fc->root is never set)

  general protection fault in security_d_instantiate
  https://syzkaller.appspot.com/bug?extid=d8a69701a6e796ad5d3e
  (lookup: squashfs_iget() returns ERR_PTR(40), which IS_ERR() does
  not catch, and d_splice_alias() dereferences it)

The second was filed under [lsm?], so it will probably stay open
unless the fix names it.  Whichever version is applied -- this one, or
"Squashfs: return -EINVAL when directory size check fails" (cc'd),
which changes the same two lines -- could carry all three reports:

Reported-by: syzbot+5d7ba5f6127ed887f459@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5d7ba5f6127ed887f459
Reported-by: syzbot+7b1d0ea11475e857d063@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7b1d0ea11475e857d063
Reported-by: syzbot+d8a69701a6e796ad5d3e@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d8a69701a6e796ad5d3e

For reference, a CBMC model check of squashfs_read_inode() as it is in
linux-next returns 40 for a long directory inode with i_size = 1.  With
this patch applied it returns only 0 or -errno for every inode type,
and squashfs_lookup() then never hands d_splice_alias() an inode that
is neither NULL nor real.  Harnesses and outputs:
https://github.com/williamchuang/linux-kernel-contributions/tree/main/squashfs-lookup-errcode

This analysis was done with the help of an AI assistant; I have
checked it and take responsibility for it.

Thanks,
William


^ permalink raw reply	[flat|nested] 2+ messages in thread
* [PATCH 1/2] squashfs: return -EINVAL on invalid directory inode size
@ 2026-11-14 14:51 Aibing Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Aibing Chen @ 2026-11-14 14:51 UTC (permalink / raw)
  To: akpm, phillip
  Cc: phillip.lougher, squashfs-devel, linux-kernel,
	syzbot+5d7ba5f6127ed887f459, syzbot+0b7a8fb8279a59e8a188,
	Aibing Chen

Commit 5213b0a08263 ("Squashfs: fix variables in directory code and
add more sanity checks") added validation of directory inode sizes to
squashfs_read_inode(), but the two new "i_size < 3" checks jump to
failed_read without setting err.  At that point err holds the number
of bytes read by squashfs_read_metadata() (32 for a directory inode,
40 for a long directory inode), so squashfs_read_inode() returns a
positive value.

squashfs_iget() wraps that in ERR_PTR(), and IS_ERR() does not catch
positive values, so the VFS happily uses the bogus "inode" pointer
and crashes:

  general protection fault in __d_obtain_alias ...
  RIP: __d_obtain_alias+0x50/0x880 fs/dcache.c:2359
  ...
  squashfs_export_iget fs/squashfs/export.c:117 [inline]
  ...

Return -EINVAL on the two new error paths.

Reported-by: syzbot+5d7ba5f6127ed887f459@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5d7ba5f6127ed887f459
Fixes: 5213b0a08263 ("Squashfs: fix variables in directory code and add more sanity checks")
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 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 5404d7ba6..4cf8a41b5 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.50.1.windows.1




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-17  0:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  0:54 [PATCH 1/2] squashfs: return -EINVAL on invalid directory inode size William Chuang
  -- strict thread matches above, loose matches on Subject: below --
2026-11-14 14:51 Aibing Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®