Squashfs: fix variable overflow triggered by sysbot
authorPhillip Lougher <phillip@squashfs.org.uk>
Mon, 13 Nov 2023 16:09:01 +0000 (16:09 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 11 Dec 2023 01:21:26 +0000 (17:21 -0800)
Sysbot reports a slab out of bounds write in squashfs_readahead().

This is ultimately caused by a file reporting an (infeasibly) large file
size (1407374883553280 bytes) with the minimum block size of 4K.

This causes variable overflow.

Link: https://lkml.kernel.org/r/20231113160901.6444-1-phillip@squashfs.org.uk
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Reported-by: syzbot+604424eb051c2f696163@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000b1fda20609ede0d1@google.com/
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/squashfs/file.c
fs/squashfs/file_direct.c

index 8ba8c4c507707817b7288f5cbcfb3b43f12185fd..e8df6430444b0143ce5bb6576233a8124914eb3c 100644 (file)
@@ -544,7 +544,8 @@ static void squashfs_readahead(struct readahead_control *ractl)
        struct squashfs_page_actor *actor;
        unsigned int nr_pages = 0;
        struct page **pages;
-       int i, file_end = i_size_read(inode) >> msblk->block_log;
+       int i;
+       loff_t file_end = i_size_read(inode) >> msblk->block_log;
        unsigned int max_pages = 1UL << shift;
 
        readahead_expand(ractl, start, (len | mask) + 1);
index f1ccad519e28ccf890831a36f462f0e3ce5ba3a1..763a3f7a75f6dd4fa6d2d6ddcb93f3faba7a974d 100644 (file)
@@ -26,10 +26,10 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
        struct inode *inode = target_page->mapping->host;
        struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
 
-       int file_end = (i_size_read(inode) - 1) >> PAGE_SHIFT;
+       loff_t file_end = (i_size_read(inode) - 1) >> PAGE_SHIFT;
        int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
-       int start_index = target_page->index & ~mask;
-       int end_index = start_index | mask;
+       loff_t start_index = target_page->index & ~mask;
+       loff_t end_index = start_index | mask;
        int i, n, pages, bytes, res = -ENOMEM;
        struct page **page;
        struct squashfs_page_actor *actor;