* [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing
@ 2026-05-28 2:48 Cunlong Li
2026-05-28 2:48 ` [PATCH v3 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li
2026-05-28 4:41 ` [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li
0 siblings, 2 replies; 3+ messages in thread
From: Cunlong Li @ 2026-05-28 2:48 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton,
Yisheng Xie
Cc: Christoph Hellwig, linux-block, linux-mm, linux-kernel,
Cunlong Li, stable
Patch 1 fixes a use-after-free in zram_bvec_write_partial() that
happens on PAGE_SIZE > 4K configurations when a partial write hits a
ZRAM_WB slot.
Patch 2 is a follow-up cleanup that drops the now-unused bio parameter
from zram_bvec_write_partial() and zram_bvec_write(), no functional
change.
Patch 1 is tagged for stable; patch 2 is not.
Signed-off-by: Cunlong Li <shenxiaogll@gmail.com>
---
Changes in v3:
- Update Fixes: tag to 8e654f8fbff5 ("zram: read page from backing
device") per Christoph.
- Link to v2: https://lore.kernel.org/r/20260527-zram-v2-0-2fb84b054b5c@gmail.com
Changes in v2:
- Add patch 2: drop the now-unused bio parameter from
zram_bvec_write_partial() and zram_bvec_write(), per Sergey's
suggestion on v1.
- Link to v1: https://lore.kernel.org/r/20260527-zram-v1-1-ce1acb2bfaf9@gmail.com
---
Cunlong Li (2):
zram: fix use-after-free in zram_bvec_write_partial()
zram: drop unused bio parameter from write helpers
drivers/block/zram/zram_drv.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
---
base-commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7
change-id: 20260526-zram-b01425b7e6c6
Best regards,
--
Cunlong Li <shenxiaogll@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/2] zram: fix use-after-free in zram_bvec_write_partial()
2026-05-28 2:48 [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li
@ 2026-05-28 2:48 ` Cunlong Li
2026-05-28 4:41 ` [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li
1 sibling, 0 replies; 3+ messages in thread
From: Cunlong Li @ 2026-05-28 2:48 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton,
Yisheng Xie
Cc: Christoph Hellwig, linux-block, linux-mm, linux-kernel,
Cunlong Li, stable
zram_read_page() picks the sync or async backing device read path
based on whether the parent bio is NULL. zram_bvec_write_partial()
passes its parent bio down, so for ZRAM_WB slots the read is
dispatched asynchronously and zram_read_page() returns 0 while the
bio is still in flight. The caller then runs memcpy_from_bvec(),
zram_write_page() and __free_page() on the buffer, leaving the
async read to write into a freed page.
zram_bvec_read_partial() was switched to NULL in commit 4e3c87b9421d
("zram: fix synchronous reads") for the same reason; the
write_partial counterpart was missed.
Fixes: 8e654f8fbff5 ("zram: read page from backing device")
Cc: Christoph Hellwig <hch@lst.de>
Cc: stable@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Cunlong Li <shenxiaogll@gmail.com>
---
drivers/block/zram/zram_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index aebc710f0d6a..b23a8bbb687c 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2333,7 +2333,7 @@ static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec,
if (!page)
return -ENOMEM;
- ret = zram_read_page(zram, page, index, bio);
+ ret = zram_read_page(zram, page, index, NULL);
if (!ret) {
memcpy_from_bvec(page_address(page) + offset, bvec);
ret = zram_write_page(zram, page, index);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing
2026-05-28 2:48 [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li
2026-05-28 2:48 ` [PATCH v3 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li
@ 2026-05-28 4:41 ` Cunlong Li
1 sibling, 0 replies; 3+ messages in thread
From: Cunlong Li @ 2026-05-28 4:41 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton,
Yisheng Xie
Cc: Christoph Hellwig, linux-block, linux-mm, linux-kernel, stable
On Thu, May 28, 2026 at 10:48:43AM +0800, Cunlong Li wrote:
> Patch 1 fixes a use-after-free in zram_bvec_write_partial() that
> happens on PAGE_SIZE > 4K configurations when a partial write hits a
> ZRAM_WB slot.
>
> Patch 2 is a follow-up cleanup that drops the now-unused bio parameter
> from zram_bvec_write_partial() and zram_bvec_write(), no functional
> change.
>
> Patch 1 is tagged for stable; patch 2 is not.
>
> Signed-off-by: Cunlong Li <shenxiaogll@gmail.com>
> ---
> Changes in v3:
> - Update Fixes: tag to 8e654f8fbff5 ("zram: read page from backing
> device") per Christoph.
> - Link to v2: https://lore.kernel.org/r/20260527-zram-v2-0-2fb84b054b5c@gmail.com
>
> Changes in v2:
> - Add patch 2: drop the now-unused bio parameter from
> zram_bvec_write_partial() and zram_bvec_write(), per Sergey's
> suggestion on v1.
> - Link to v1: https://lore.kernel.org/r/20260527-zram-v1-1-ce1acb2bfaf9@gmail.com
>
> ---
> Cunlong Li (2):
> zram: fix use-after-free in zram_bvec_write_partial()
> zram: drop unused bio parameter from write helpers
>
> drivers/block/zram/zram_drv.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
> ---
> base-commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7
> change-id: 20260526-zram-b01425b7e6c6
>
> Best regards,
> --
> Cunlong Li <shenxiaogll@gmail.com>
>
Test results for reference:
Tested on arm64 16K-page QEMU (Apple M4, HVF) with KASAN enabled,
kernel v7.1-rc5 (base-commit e8c2f9fdadee). zram0 backed by a loop
file on ext4, fio bs=4k randrw (4 jobs, 120s) against ext4-on-zram0
with a parallel loop triggering idle writeback.
Without the fix, KASAN fires within seconds:
BUG: KASAN: use-after-free in copy_folio_from_iter_atomic+0x830/0x18e8
Read of size 16384 at addr ffff8000d1168000 by task kworker/u16:4/321
Workqueue: loop0 loop_rootcg_workfn
Call trace:
memcpy+0x3c/0x9c
copy_folio_from_iter_atomic+0x830/0x18e8
generic_perform_write+0x308/0x558
ext4_buffered_write_iter+0x140/0x438
ext4_file_write_iter+0x868/0x1004
lo_rw_aio.isra.0+0x838/0xc94
loop_process_work+0x2f8/0xdf0
loop_rootcg_workfn+0x20/0x2c
process_one_work+0x560/0xc10
page: refcount:0 mapcount:0
The async backing-device read bio still references the page after
zram_bvec_write_partial() freed it; the loop worker then writes
into freed memory.
With the series applied, the same workload runs clean for two
minutes with no KASAN reports.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-28 4:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28 2:48 [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li
2026-05-28 2:48 ` [PATCH v3 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li
2026-05-28 4:41 ` [PATCH v3 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox