From: Lizhi Xu <lizhi.xu@windriver.com>
To: <lizhi.xu@windriver.com>
Cc: <brauner@kernel.org>, <jack@suse.cz>,
<linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<phillip@squashfs.org.uk>, <squashfs-devel@lists.sourceforge.net>,
<syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com>,
<syzkaller-bugs@googlegroups.com>, <viro@zeniv.linux.org.uk>
Subject: [PATCH V7] squashfs: Add symlink size check in squash_read_inode
Date: Sat, 3 Aug 2024 15:43:49 +0800 [thread overview]
Message-ID: <20240803074349.3599957-1-lizhi.xu@windriver.com> (raw)
In-Reply-To: <20240803040729.1677477-1-lizhi.xu@windriver.com>
syzbot report KMSAN: uninit-value in pick_link, the root cause is that
squashfs_symlink_read_folio did not check the length, resulting in folio
not being initialized and did not return the corresponding error code.
The length is calculated from i_size, this case is about symlink, so i_size
value is derived from symlink_size, so it is necessary to add a check to
confirm that symlink_size value is valid, otherwise an error -EINVAL will
be returned.
If symlink_size is too large, it may result in a negative value when
calculating length in squashfs_symlink_read_folio due to int overflow,
and its value must be greater than PAGE_SIZE at this time.
Reported-and-tested-by: syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=24ac24ff58dc5b0d26b9
Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
---
fs/squashfs/inode.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c
index 16bd693d0b3a..bed6764e4461 100644
--- a/fs/squashfs/inode.c
+++ b/fs/squashfs/inode.c
@@ -273,14 +273,21 @@ int squashfs_read_inode(struct inode *inode, long long ino)
case SQUASHFS_SYMLINK_TYPE:
case SQUASHFS_LSYMLINK_TYPE: {
struct squashfs_symlink_inode *sqsh_ino = &squashfs_ino.symlink;
+ loff_t symlink_size;
err = squashfs_read_metadata(sb, sqsh_ino, &block, &offset,
sizeof(*sqsh_ino));
if (err < 0)
goto failed_read;
+ symlink_size = le32_to_cpu(sqsh_ino->symlink_size);
+ if (symlink_size > PAGE_SIZE) {
+ ERROR("Corrupted symlink, size [%llu]\n", symlink_size);
+ return -EINVAL;
+ }
+
set_nlink(inode, le32_to_cpu(sqsh_ino->nlink));
- inode->i_size = le32_to_cpu(sqsh_ino->symlink_size);
+ inode->i_size = symlink_size;
inode->i_op = &squashfs_symlink_inode_ops;
inode_nohighmem(inode);
inode->i_data.a_ops = &squashfs_symlink_aops;
--
2.43.0
next prev parent reply other threads:[~2024-08-03 7:44 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 8:12 [syzbot] [squashfs?] KMSAN: uninit-value in pick_link syzbot
2024-08-01 2:27 ` [PATCH] filemap: Init the newly allocated folio memory to 0 for the filemap Lizhi Xu
2024-08-01 2:58 ` Al Viro
2024-08-01 5:28 ` Lizhi Xu
2024-08-01 7:10 ` Al Viro
2024-08-01 7:24 ` Al Viro
2024-08-01 8:12 ` Lizhi Xu
2024-08-01 9:13 ` Lizhi Xu
2024-08-01 12:42 ` Al Viro
2024-08-01 15:17 ` [PATCH V2] squashfs: Add length check in squashfs_symlink_read_folio Lizhi Xu
2024-08-01 15:30 ` Jan Kara
2024-08-02 1:39 ` Lizhi Xu
2024-08-02 1:50 ` [PATCH V3] squashfs: Add i_size check in squash_read_inode Lizhi Xu
2024-08-02 3:01 ` [PATCH V4] " Lizhi Xu
2024-08-02 9:33 ` Jan Kara
2024-08-02 11:16 ` [PATCH V5] " Lizhi Xu
2024-08-02 13:52 ` Al Viro
2024-08-02 14:44 ` [PATCH] filemap: Init the newly allocated folio memory to 0 for the filemap Lizhi Xu
2024-08-02 15:03 ` Al Viro
2024-08-03 4:07 ` [PATCH V6] squashfs: Add symlink size check in squash_read_inode Lizhi Xu
2024-08-03 7:43 ` Lizhi Xu [this message]
2024-08-04 21:16 ` [PATCH V7] " Phillip Lougher
2024-08-04 21:20 ` Al Viro
2024-08-04 22:31 ` Phillip Lougher
2024-08-05 7:03 ` Christian Brauner
2024-08-05 1:02 ` Lizhi Xu
2024-08-05 1:40 ` Al Viro
2024-08-06 2:56 ` Lizhi Xu
2024-08-06 4:59 ` Al Viro
2024-08-06 6:19 ` Lizhi Xu
2024-08-06 6:58 ` Al Viro
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=20240803074349.3599957-1-lizhi.xu@windriver.com \
--to=lizhi.xu@windriver.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=phillip@squashfs.org.uk \
--cc=squashfs-devel@lists.sourceforge.net \
--cc=syzbot+24ac24ff58dc5b0d26b9@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).