summaryrefslogtreecommitdiffstats
path: root/fs/squashfs/fragment.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-02 08:43:35 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-02 09:32:23 -0700
commit71755ee5350b63fb1f283de8561cdb61b47f4d1d (patch)
treecfca6c7e5f8f30014724b955c845a1a2e80d95e5 /fs/squashfs/fragment.c
parent6b4703768268d09ac928c64474fd686adf4574f9 (diff)
downloadlinux-71755ee5350b63fb1f283de8561cdb61b47f4d1d.tar.gz
linux-71755ee5350b63fb1f283de8561cdb61b47f4d1d.tar.bz2
linux-71755ee5350b63fb1f283de8561cdb61b47f4d1d.zip
squashfs: more metadata hardening
The squashfs fragment reading code doesn't actually verify that the fragment is inside the fragment table. The end result _is_ verified to be inside the image when actually reading the fragment data, but before that is done, we may end up taking a page fault because the fragment table itself might not even exist. Another report from Anatoly and his endless squashfs image fuzzing. Reported-by: Анатолий Тросиненко <anatoly.trosinenko@gmail.com> Acked-by:: Phillip Lougher <phillip.lougher@gmail.com>, Cc: Willy Tarreau <w@1wt.eu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/squashfs/fragment.c')
-rw-r--r--fs/squashfs/fragment.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/fs/squashfs/fragment.c b/fs/squashfs/fragment.c
index 86ad9a4b8c36..0681feab4a84 100644
--- a/fs/squashfs/fragment.c
+++ b/fs/squashfs/fragment.c
@@ -49,11 +49,16 @@ int squashfs_frag_lookup(struct super_block *sb, unsigned int fragment,
u64 *fragment_block)
{
struct squashfs_sb_info *msblk = sb->s_fs_info;
- int block = SQUASHFS_FRAGMENT_INDEX(fragment);
- int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
- u64 start_block = le64_to_cpu(msblk->fragment_index[block]);
+ int block, offset, size;
struct squashfs_fragment_entry fragment_entry;
- int size;
+ u64 start_block;
+
+ if (fragment >= msblk->fragments)
+ return -EIO;
+ block = SQUASHFS_FRAGMENT_INDEX(fragment);
+ offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
+
+ start_block = le64_to_cpu(msblk->fragment_index[block]);
size = squashfs_read_metadata(sb, &fragment_entry, &start_block,
&offset, sizeof(fragment_entry));