mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
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/20241020232200.837231-1-phillip@squashfs.org.uk Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> Reported-by: "Lai, Yi" <yi1.lai@linux.intel.com> Closes: https://lore.kernel.org/all/ZwzcnCAosIPqQ9Ie@ly-workstation/ Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
330d8df81f
commit
d31638ff6c
@ -30,7 +30,8 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
|
|||||||
int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
|
int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
|
||||||
loff_t start_index = folio->index & ~mask;
|
loff_t start_index = folio->index & ~mask;
|
||||||
loff_t end_index = start_index | mask;
|
loff_t end_index = start_index | mask;
|
||||||
int i, n, pages, bytes, res = -ENOMEM;
|
loff_t index;
|
||||||
|
int i, pages, bytes, res = -ENOMEM;
|
||||||
struct page **page, *last_page;
|
struct page **page, *last_page;
|
||||||
struct squashfs_page_actor *actor;
|
struct squashfs_page_actor *actor;
|
||||||
void *pageaddr;
|
void *pageaddr;
|
||||||
@ -45,9 +46,9 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
/* Try to grab all the pages covered by the Squashfs block */
|
/* Try to grab all the pages covered by the Squashfs block */
|
||||||
for (i = 0, n = start_index; n <= end_index; n++) {
|
for (i = 0, index = start_index; index <= end_index; index++) {
|
||||||
page[i] = (n == folio->index) ? target_page :
|
page[i] = (index == folio->index) ? target_page :
|
||||||
grab_cache_page_nowait(target_page->mapping, n);
|
grab_cache_page_nowait(target_page->mapping, index);
|
||||||
|
|
||||||
if (page[i] == NULL)
|
if (page[i] == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user