Skip to content

Commit 94c43de

Browse files
committed
erofs: fix wrong primary bvec selection on deduplicated extents
When handling deduplicated compressed data, there can be multiple decompressed extents pointing to the same compressed data in one shot. In such cases, the bvecs which belong to the longest extent will be selected as the primary bvecs for real decompressors to decode and the other duplicated bvecs will be directly copied from the primary bvecs. Previously, only relative offsets of the longest extent were checked to decompress the primary bvecs. On rare occasions, it can be incorrect if there are several extents with the same start relative offset. As a result, some short bvecs could be selected for decompression and then cause data corruption. For example, as Shijie Sun reported off-list, considering the following extents of a file: 117: 903345.. 915250 | 11905 : 385024.. 389120 | 4096 ... 119: 919729.. 930323 | 10594 : 385024.. 389120 | 4096 ... 124: 968881.. 980786 | 11905 : 385024.. 389120 | 4096 The start relative offset is the same: 2225, but extent 119 (919729.. 930323) is shorter than the others. Let's restrict the bvec length in addition to the start offset if bvecs are not full. Reported-by: Shijie Sun <sunshijie@xiaomi.com> Fixes: 5c2a642 ("erofs: introduce partial-referenced pclusters") Tested-by Shijie Sun <sunshijie@xiaomi.com> Reviewed-by: Yue Hu <huyue2@coolpad.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230719065459.60083-1-hsiangkao@linux.alibaba.com
1 parent 5d0c230 commit 94c43de

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/erofs/zdata.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,11 @@ static void z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend *be,
11441144
struct z_erofs_bvec *bvec)
11451145
{
11461146
struct z_erofs_bvec_item *item;
1147+
unsigned int pgnr;
11471148

1148-
if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK)) {
1149-
unsigned int pgnr;
1150-
1149+
if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK) &&
1150+
(bvec->end == PAGE_SIZE ||
1151+
bvec->offset + bvec->end == be->pcl->length)) {
11511152
pgnr = (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT;
11521153
DBG_BUGON(pgnr >= be->nr_pages);
11531154
if (!be->decompressed_pages[pgnr]) {

0 commit comments

Comments
 (0)