linux-stable/fs/erofs
Gao Xiang be3f603583 erofs: fix unsafe pagevec reuse of hooked pclusters
commit 86432a6dca upstream.

There are pclusters in runtime marked with Z_EROFS_PCLUSTER_TAIL
before actual I/O submission. Thus, the decompression chain can be
extended if the following pcluster chain hooks such tail pcluster.

As the related comment mentioned, if some page is made of a hooked
pcluster and another followed pcluster, it can be reused for in-place
I/O (since I/O should be submitted anyway):
 _______________________________________________________________
|  tail (partial) page |          head (partial) page           |
|_____PRIMARY_HOOKED___|____________PRIMARY_FOLLOWED____________|

However, it's by no means safe to reuse as pagevec since if such
PRIMARY_HOOKED pclusters finally move into bypass chain without I/O
submission. It's somewhat hard to reproduce with LZ4 and I just found
it (general protection fault) by ro_fsstressing a LZMA image for long
time.

I'm going to actively clean up related code together with multi-page
folio adaption in the next few months. Let's address it directly for
easier backporting for now.

Call trace for reference:
  z_erofs_decompress_pcluster+0x10a/0x8a0 [erofs]
  z_erofs_decompress_queue.isra.36+0x3c/0x60 [erofs]
  z_erofs_runqueue+0x5f3/0x840 [erofs]
  z_erofs_readahead+0x1e8/0x320 [erofs]
  read_pages+0x91/0x270
  page_cache_ra_unbounded+0x18b/0x240
  filemap_get_pages+0x10a/0x5f0
  filemap_read+0xa9/0x330
  new_sync_read+0x11b/0x1a0
  vfs_read+0xf1/0x190

Link: https://lore.kernel.org/r/20211103182006.4040-1-xiang@kernel.org
Fixes: 3883a79abd ("staging: erofs: introduce VLE decompression support")
Cc: <stable@vger.kernel.org> # 4.19+
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-21 13:46:37 +01:00
..
compress.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
data.c erofs: avoid using generic_block_bmap 2020-12-30 11:53:46 +01:00
decompressor.c erofs: don't trigger WARN() when decompression fails 2021-11-18 14:04:01 +01:00
dir.c erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
erofs_fs.h erofs: add unsupported inode i_format check 2021-05-11 14:47:13 +02:00
inode.c erofs: add unsupported inode i_format check 2021-05-11 14:47:13 +02:00
internal.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
Kconfig erofs: support superblock checksum 2019-11-24 11:02:41 +08:00
Makefile
namei.c erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
super.c erofs: fix error return code in erofs_read_superblock() 2021-07-14 16:56:53 +02:00
tagptr.h
utils.c erofs: fold in used-once helper erofs_workgroup_unfreeze_final() 2020-08-03 21:04:46 +08:00
xattr.c erofs: initialized fields can only be observed after bit is set 2021-03-04 11:38:28 +01:00
xattr.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
zdata.c erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-21 13:46:37 +01:00
zdata.h erofs: Replace HTTP links with HTTPS ones 2020-08-03 21:04:29 +08:00
zmap.c erofs: initialized fields can only be observed after bit is set 2021-03-04 11:38:28 +01:00
zpvec.h erofs: fix unsafe pagevec reuse of hooked pclusters 2021-11-21 13:46:37 +01:00