From: Fox Chen <foxhlchen@gmail.com>
To: phillip@squashfs.org.uk
Cc: Fox Chen <foxhlchen@gmail.com>,
linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
syzbot+8e28bba73ed1772a6802@syzkaller.appspotmail.com
Subject: [PATCH] squashfs: Add id_table sanity check to squashfs_get_id
Date: Tue, 3 Nov 2020 10:04:31 +0800 [thread overview]
Message-ID: <20201103020431.147711-1-foxhlchen@gmail.com> (raw)
When uid/gid info in superblocks or id_index_table is corrupted,
The uid/gid index can be larger than the size of msblk->id_table.
This is reported by syzkaller.
This patch adds a sanity check to squashfs_get_id which calculates
the max available room for uid/gid table by doing
msblk->xattr_table - msblk->id_table[0]
and check if index is larger than this.
While this provides some sort of check, it is
imperfect because id_table can be smaller than that.
Reported-by: syzbot+8e28bba73ed1772a6802@syzkaller.appspotmail.com
Signed-off-by: Fox Chen <foxhlchen@gmail.com>
---
fs/squashfs/id.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/squashfs/id.c b/fs/squashfs/id.c
index 6be5afe7287d..81bd67c0f649 100644
--- a/fs/squashfs/id.c
+++ b/fs/squashfs/id.c
@@ -35,10 +35,16 @@ int squashfs_get_id(struct super_block *sb, unsigned int index,
struct squashfs_sb_info *msblk = sb->s_fs_info;
int block = SQUASHFS_ID_BLOCK(index);
int offset = SQUASHFS_ID_BLOCK_OFFSET(index);
- u64 start_block = le64_to_cpu(msblk->id_table[block]);
+ u64 start_block;
__le32 disk_id;
int err;
+ // sanity check
+ if (le64_to_cpu(msblk->id_table[0]) + block >= msblk->xattr_table)
+ return -EINVAL;
+
+ start_block = le64_to_cpu(msblk->id_table[block]);
+
err = squashfs_read_metadata(sb, &disk_id, &start_block, &offset,
sizeof(disk_id));
if (err < 0)
--
2.25.1
reply other threads:[~2020-11-03 2:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20201103020431.147711-1-foxhlchen@gmail.com \
--to=foxhlchen@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=phillip@squashfs.org.uk \
--cc=syzbot+8e28bba73ed1772a6802@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;
as well as URLs for NNTP newsgroup(s).