Skip to content

Commit d31638f

Browse files
plougherakpm00
authored andcommitted
Squashfs: fix variable overflow in squashfs_readpage_block
Syzbot reports a slab out of bounds access in squashfs_readpage_block(). This is caused by an attempt to read page index 0x2000000000. This value (start_index) is stored in an integer loop variable which overflows producing a value of 0. This causes a loop which iterates over pages start_index -> end_index to iterate over 0 -> end_index, which ultimately causes an out of bounds page array access. Fix by changing variable to a loff_t, and rename to index to make it clearer it is a page index, and not a loop count. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Phillip Lougher <[email protected]> Reported-by: "Lai, Yi" <[email protected]> Closes: https://lore.kernel.org/all/ZwzcnCAosIPqQ9Ie@ly-workstation/ Signed-off-by: Andrew Morton <[email protected]>
1 parent 330d8df commit d31638f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

fs/squashfs/file_direct.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
3030
int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
3131
loff_t start_index = folio->index & ~mask;
3232
loff_t end_index = start_index | mask;
33-
int i, n, pages, bytes, res = -ENOMEM;
33+
loff_t index;
34+
int i, pages, bytes, res = -ENOMEM;
3435
struct page **page, *last_page;
3536
struct squashfs_page_actor *actor;
3637
void *pageaddr;
@@ -45,9 +46,9 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
4546
return res;
4647

4748
/* Try to grab all the pages covered by the Squashfs block */
48-
for (i = 0, n = start_index; n <= end_index; n++) {
49-
page[i] = (n == folio->index) ? target_page :
50-
grab_cache_page_nowait(target_page->mapping, n);
49+
for (i = 0, index = start_index; index <= end_index; index++) {
50+
page[i] = (index == folio->index) ? target_page :
51+
grab_cache_page_nowait(target_page->mapping, index);
5152

5253
if (page[i] == NULL)
5354
continue;

0 commit comments

Comments
 (0)