Skip to content

Commit ff3a75b

Browse files
ploughergregkh
authored andcommitted
squashfs: avoid out of bounds writes in decompressors
commit e812cbb upstream. Patch series "Squashfs: fix BIO migration regression and add sanity checks". Patch [1/4] fixes a regression introduced by the "migrate from ll_rw_block usage to BIO" patch, which has produced a number of Sysbot/Syzkaller reports. Patches [2/4], [3/4], and [4/4] fix a number of filesystem corruption issues which have produced Sysbot reports in the id, inode and xattr lookup code. Each patch has been tested against the Sysbot reproducers using the given kernel configuration. They have the appropriate "Reported-by:" lines added. Additionally, all of the reproducer filesystems are indirectly fixed by patch [4/4] due to the fact they all have xattr corruption which is now detected there. Additional testing with other configurations and architectures (32bit, big endian), and normal filesystems has also been done to trap any inadvertent regressions caused by the additional sanity checks. This patch (of 4): This is a regression introduced by the patch "migrate from ll_rw_block usage to BIO". Sysbot/Syskaller has reported a number of "out of bounds writes" and "unable to handle kernel paging request in squashfs_decompress" errors which have been identified as a regression introduced by the above patch. Specifically, the patch removed the following sanity check if (length < 0 || length > output->length || (index + length) > msblk->bytes_used) This check did two things: 1. It ensured any reads were not beyond the end of the filesystem 2. It ensured that the "length" field read from the filesystem was within the expected maximum length. Without this any corrupted values can over-run allocated buffers. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 93e72b3 ("squashfs: migrate from ll_rw_block usage to BIO") Reported-by: [email protected] Signed-off-by: Phillip Lougher <[email protected]> Cc: Philippe Liard <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent dd0a41b commit ff3a75b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/squashfs/block.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,15 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
196196
length = SQUASHFS_COMPRESSED_SIZE(length);
197197
index += 2;
198198

199-
TRACE("Block @ 0x%llx, %scompressed size %d\n", index,
199+
TRACE("Block @ 0x%llx, %scompressed size %d\n", index - 2,
200200
compressed ? "" : "un", length);
201201
}
202+
if (length < 0 || length > output->length ||
203+
(index + length) > msblk->bytes_used) {
204+
res = -EIO;
205+
goto out;
206+
}
207+
202208
if (next_index)
203209
*next_index = index + length;
204210

0 commit comments

Comments
 (0)