Re: [RFC PATCH v4 2/4] zram: support compression at the granularity of multi-pages
From: Nanzhe Zhao
Date: Fri Nov 27 2026 - 03:29:05 EST
> [Severity: High]
> Does passing bio as parent to zram_read_page_size() cause a use-after-free
> of page when ZRAM_WB is set?
>
> When test_slot_flag(zram, index, ZRAM_WB) is true, zram_read_page_size()
> calls read_from_bdev(zram, page, index, blk_idx, parent) with a non-NULL
> parent bio:
> ...
> read_from_bdev_async() submits an asynchronous child bio referencing page
> (inheriting REQ_OP_WRITE from the write bio) and returns 0 immediately,
> after which zram_bvec_write_multi_pages_partial() frees page via
> __free_pages() while the backing-device I/O and completion work are still
> using it.
Both writeback and recompression currently assume that each slot holds a
single PAGE_SIZE object, which conflicts with multi-page slots, so I plan
to temporarily make CONFIG_ZRAM_MULTI_PAGES mutually exclusive with
CONFIG_ZRAM_WRITEBACK and CONFIG_ZRAM_MULTI_COMP via Kconfig.
> [Severity: High]
> Can post-processing a multi-page slot overflow ctl->pp_buckets[] and
> req->page?
>
> Neither scan_slots_for_writeback() nor scan_slots_for_recompress() skips
> ZRAM_COMP_MULTI_PAGES slots, where get_slot_size() can be up to
> ZCOMP_MULTI_PAGES_SIZE. In place_pp_slot(), NUM_PP_BUCKETS is sized for
> PAGE_SIZE:
> ...
> When a multi-page slot's compressed size exceeds PAGE_SIZE, bid exceeds
> NUM_PP_BUCKETS and corrupts memory past struct zram_pp_ctl. In
> zram_writeback_slots(), req->page is a single PAGE_SIZE page, so
> read_from_zspool_raw() also overflows req->page and wraps PAGE_SIZE - size
> in memzero_page(), while uncompressed writeback and recompress_slot() pass
> PAGE_SIZE for a multi-page object.
Same here. With writeback and recompression disabled under
CONFIG_ZRAM_MULTI_PAGES, scan_slots_for_writeback(),
scan_slots_for_recompress(), and place_pp_slot() will not be built or
called on multi-page slots.
Also regarding the related zs_rebind_handle() issue from the patch 1 review:
> [Severity: High]
> Does zs_rebind_handle() also need to mask the object offset with
> page_size - 1 instead of offset_in_page()?
>
> When a non-huge multi-page object sits at an offset >= PAGE_SIZE within its
> zpdesc, zs_rebind_handle() overwrites 8 bytes in the first subpage and leaves
> the object's own header pointing to the old src handle, so later compaction
> updates src instead of dst.
This is tied to the same recompression issue: zs_rebind_handle() is only
called by zram's recompress_slot(). With CONFIG_ZRAM_MULTI_COMP and
CONFIG_ZRAM_MULTI_PAGES mutually exclusive via Kconfig, multi-page objects
will never reach zs_rebind_handle().