Skip to content

Commit

Permalink
staging: erofs: detect potential multiref due to corrupted images
Browse files Browse the repository at this point in the history
As reported by erofs-utils fuzzer, currently, multiref
(ondisk deduplication) hasn't been supported for now,
we should forbid it properly.

Fixes: 3883a79 ("staging: erofs: introduce VLE decompression support")
Cc: <stable@vger.kernel.org> # 4.19+
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Link: https://lore.kernel.org/r/20190821140152.229648-1-gaoxiang25@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Gao Xiang authored and Greg Kroah-Hartman committed Aug 21, 2019
1 parent 8467c3b commit e12a0ce
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions drivers/staging/erofs/zdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ static int z_erofs_decompress_pcluster(struct super_block *sb,
for (i = 0; i < nr_pages; ++i)
pages[i] = NULL;

err = 0;
z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS,
cl->pagevec, 0);

Expand All @@ -819,16 +820,24 @@ static int z_erofs_decompress_pcluster(struct super_block *sb,
pagenr = z_erofs_onlinepage_index(page);

DBG_BUGON(pagenr >= nr_pages);
DBG_BUGON(pages[pagenr]);

/*
* currently EROFS doesn't support multiref(dedup),
* so here erroring out one multiref page.
*/
if (unlikely(pages[pagenr])) {
DBG_BUGON(1);
SetPageError(pages[pagenr]);
z_erofs_onlinepage_endio(pages[pagenr]);
err = -EFSCORRUPTED;
}
pages[pagenr] = page;
}
z_erofs_pagevec_ctor_exit(&ctor, true);

overlapped = false;
compressed_pages = pcl->compressed_pages;

err = 0;
for (i = 0; i < clusterpages; ++i) {
unsigned int pagenr;

Expand All @@ -852,7 +861,12 @@ static int z_erofs_decompress_pcluster(struct super_block *sb,
pagenr = z_erofs_onlinepage_index(page);

DBG_BUGON(pagenr >= nr_pages);
DBG_BUGON(pages[pagenr]);
if (unlikely(pages[pagenr])) {
DBG_BUGON(1);
SetPageError(pages[pagenr]);
z_erofs_onlinepage_endio(pages[pagenr]);
err = -EFSCORRUPTED;
}
pages[pagenr] = page;

overlapped = true;
Expand Down

0 comments on commit e12a0ce

Please sign in to comment.