linux-stable/fs/erofs
Gao Xiang b845249a4e erofs: fix wrong primary bvec selection on deduplicated extents
[ Upstream commit 94c43de735 ]

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: 5c2a64252c ("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
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-08-11 12:14:08 +02:00
..
compress.h erofs: introduce multi-reference pclusters (fully-referenced) 2022-07-22 21:44:27 +08:00
data.c erofs: keep meta inode into erofs_buf 2023-04-17 01:15:50 +08:00
decompressor.c erofs: avoid hardcoded blocksize for subpage block support 2023-04-17 01:15:44 +08:00
decompressor_lzma.c erofs: avoid hardcoded blocksize for subpage block support 2023-04-17 01:15:44 +08:00
dir.c erofs: keep meta inode into erofs_buf 2023-04-17 01:15:50 +08:00
erofs_fs.h erofs: cleanup i_format-related stuffs 2023-04-17 01:15:55 +08:00
fscache.c erofs: avoid hardcoded blocksize for subpage block support 2023-04-17 01:15:44 +08:00
inode.c erofs: fix fsdax unavailability for chunk-based regular files 2023-07-23 13:53:47 +02:00
internal.h erofs: avoid pcpubuf.c inclusion if CONFIG_EROFS_FS_ZIP is off 2023-05-23 16:56:40 +08:00
Kconfig erofs: use HIPRI by default if per-cpu kthreads are enabled 2023-05-23 16:57:08 +08:00
Makefile erofs: avoid pcpubuf.c inclusion if CONFIG_EROFS_FS_ZIP is off 2023-05-23 16:56:40 +08:00
namei.c erofs: sunset erofs_dbg() 2023-04-17 01:15:54 +08:00
pcpubuf.c erofs: mark z_erofs_lzma_init/erofs_pcpubuf_init w/ __init 2023-03-09 22:49:30 +08:00
super.c erofs: enable long extended attribute name prefixes 2023-04-17 01:15:53 +08:00
sysfs.c erofs: make kobj_type structures constant 2023-02-15 08:11:26 +08:00
utils.c mm: shrinkers: provide shrinkers with names 2022-07-03 18:08:40 -07:00
xattr.c erofs: fix null-ptr-deref caused by erofs_xattr_prefixes_init 2023-05-23 16:56:21 +08:00
xattr.h Changes since last update: 2023-04-24 14:25:39 -07:00
zdata.c erofs: fix wrong primary bvec selection on deduplicated extents 2023-08-11 12:14:08 +02:00
zmap.c erofs: fix compact 4B support for 16k block size 2023-07-19 16:35:12 +02:00