mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: akpm@linux-foundation.org, phillip@squashfs.org.uk
Cc: phillip.lougher@gmail.com, squashfs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org,
	syzbot+5d7ba5f6127ed887f459@syzkaller.appspotmail.com,
	syzbot+0b7a8fb8279a59e8a188@syzkaller.appspotmail.com,
	Aibing Chen <chenaibing@cmss.chinamobile.com>
Subject: [PATCH 1/2] squashfs: return -EINVAL on invalid directory inode size
Date: Sat, 14 Nov 2026 22:51:27 +0800	[thread overview]
Message-ID: <20261114145128.625-1-chenaibing@cmss.chinamobile.com> (raw)

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




             reply	other threads:[~2026-11-14 14:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 14:51 Aibing Chen [this message]
2026-11-14 14:51 ` [PATCH 2/2] squashfs: return -EIO on out-of-bounds directory entry in lookup Aibing Chen
2026-11-17  0:54 [PATCH 1/2] squashfs: return -EINVAL on invalid directory inode size William Chuang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261114145128.625-1-chenaibing@cmss.chinamobile.com \
    --to=chenaibing@cmss.chinamobile.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip.lougher@gmail.com \
    --cc=phillip@squashfs.org.uk \
    --cc=squashfs-devel@lists.sourceforge.net \
    --cc=syzbot+0b7a8fb8279a59e8a188@syzkaller.appspotmail.com \
    --cc=syzbot+5d7ba5f6127ed887f459@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®