* [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing
@ 2026-05-27 4:49 Cunlong Li
2026-05-27 4:49 ` [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Cunlong Li @ 2026-05-27 4:49 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton
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 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] 8+ messages in thread* [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() 2026-05-27 4:49 [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li @ 2026-05-27 4:49 ` Cunlong Li 2026-05-27 7:24 ` Christoph Hellwig 2026-05-27 4:49 ` [PATCH v2 2/2] zram: drop unused bio parameter from write helpers Cunlong Li 2026-05-27 7:21 ` [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Sergey Senozhatsky 2 siblings, 1 reply; 8+ messages in thread From: Cunlong Li @ 2026-05-27 4:49 UTC (permalink / raw) To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton 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: 4e3c87b9421d ("zram: fix synchronous reads") Cc: Christoph Hellwig <hch@lst.de> Cc: stable@vger.kernel.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] 8+ messages in thread
* Re: [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() 2026-05-27 4:49 ` [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li @ 2026-05-27 7:24 ` Christoph Hellwig 2026-05-27 14:13 ` Cunlong Li 0 siblings, 1 reply; 8+ messages in thread From: Christoph Hellwig @ 2026-05-27 7:24 UTC (permalink / raw) To: Cunlong Li Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton, Christoph Hellwig, linux-block, linux-mm, linux-kernel, stable On Wed, May 27, 2026 at 12:49:24PM +0800, Cunlong Li wrote: > 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: 4e3c87b9421d ("zram: fix synchronous reads") That's just the last patch touching the line. This bio chaining goes further back. AFAICS all the way to introducing backing device support in: 8e654f8fbff5 ("zram: read page from backing device") The patch itself looks good, though: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() 2026-05-27 7:24 ` Christoph Hellwig @ 2026-05-27 14:13 ` Cunlong Li 0 siblings, 0 replies; 8+ messages in thread From: Cunlong Li @ 2026-05-27 14:13 UTC (permalink / raw) To: Christoph Hellwig Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton, linux-block, linux-mm, linux-kernel, stable On Wed, May 27, 2026 at 09:24:14AM +0200, Christoph Hellwig wrote: > On Wed, May 27, 2026 at 12:49:24PM +0800, Cunlong Li wrote: > > 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: 4e3c87b9421d ("zram: fix synchronous reads") > > That's just the last patch touching the line. This bio chaining goes > further back. AFAICS all the way to introducing backing device support > in: 8e654f8fbff5 ("zram: read page from backing device") You're right, thanks for catching this -- will fix in v3 with: Fixes: 8e654f8fbff5 ("zram: read page from backing device") > > The patch itself looks good, though: > > Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] zram: drop unused bio parameter from write helpers 2026-05-27 4:49 [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li 2026-05-27 4:49 ` [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li @ 2026-05-27 4:49 ` Cunlong Li 2026-05-27 7:24 ` Christoph Hellwig 2026-05-27 7:21 ` [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Sergey Senozhatsky 2 siblings, 1 reply; 8+ messages in thread From: Cunlong Li @ 2026-05-27 4:49 UTC (permalink / raw) To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton Cc: Christoph Hellwig, linux-block, linux-mm, linux-kernel, Cunlong Li After the previous fix, zram_bvec_write_partial() always passes NULL to zram_read_page() and no longer needs the parent bio. Mirror the read side (zram_bvec_read_partial() has not taken a bio since commit 4e3c87b9421d ("zram: fix synchronous reads")) and drop the parameter from zram_bvec_write_partial() and zram_bvec_write(). No functional change. Signed-off-by: Cunlong Li <shenxiaogll@gmail.com> --- drivers/block/zram/zram_drv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index b23a8bbb687c..66347915a2cc 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2325,7 +2325,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index) * This is a partial IO. Read the full page before writing the changes. */ static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + u32 index, int offset) { struct page *page = alloc_page(GFP_NOIO); int ret; @@ -2343,10 +2343,10 @@ static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec, } static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + u32 index, int offset) { if (is_partial_io(bvec)) - return zram_bvec_write_partial(zram, bvec, index, offset, bio); + return zram_bvec_write_partial(zram, bvec, index, offset); return zram_write_page(zram, bvec->bv_page, index); } @@ -2743,7 +2743,7 @@ static void zram_bio_write(struct zram *zram, struct bio *bio) bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset); - if (zram_bvec_write(zram, &bv, index, offset, bio) < 0) { + if (zram_bvec_write(zram, &bv, index, offset) < 0) { atomic64_inc(&zram->stats.failed_writes); bio->bi_status = BLK_STS_IOERR; break; -- 2.30.2 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] zram: drop unused bio parameter from write helpers 2026-05-27 4:49 ` [PATCH v2 2/2] zram: drop unused bio parameter from write helpers Cunlong Li @ 2026-05-27 7:24 ` Christoph Hellwig 0 siblings, 0 replies; 8+ messages in thread From: Christoph Hellwig @ 2026-05-27 7:24 UTC (permalink / raw) To: Cunlong Li Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton, Christoph Hellwig, linux-block, linux-mm, linux-kernel Looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing 2026-05-27 4:49 [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li 2026-05-27 4:49 ` [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li 2026-05-27 4:49 ` [PATCH v2 2/2] zram: drop unused bio parameter from write helpers Cunlong Li @ 2026-05-27 7:21 ` Sergey Senozhatsky 2026-05-27 14:15 ` Cunlong Li 2 siblings, 1 reply; 8+ messages in thread From: Sergey Senozhatsky @ 2026-05-27 7:21 UTC (permalink / raw) To: Cunlong Li Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Andrew Morton, Christoph Hellwig, linux-block, linux-mm, linux-kernel, stable On (26/05/27 12:49), 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. Did you test it? Looks reasonable (unless I'm missing something): Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing 2026-05-27 7:21 ` [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Sergey Senozhatsky @ 2026-05-27 14:15 ` Cunlong Li 0 siblings, 0 replies; 8+ messages in thread From: Cunlong Li @ 2026-05-27 14:15 UTC (permalink / raw) To: Sergey Senozhatsky Cc: Minchan Kim, Jens Axboe, Andrew Morton, Christoph Hellwig, linux-block, linux-mm, linux-kernel, stable On Wed, May 27, 2026 at 04:21:53PM +0900, Sergey Senozhatsky wrote: > On (26/05/27 12:49), 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. > > Did you test it? Compile-tested only so far; I haven't had a chance to run a PAGE_SIZE > 4K reproducer yet. Thanks for the review. > > Looks reasonable (unless I'm missing something): > Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-05-27 14:16 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-05-27 4:49 [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Cunlong Li 2026-05-27 4:49 ` [PATCH v2 1/2] zram: fix use-after-free in zram_bvec_write_partial() Cunlong Li 2026-05-27 7:24 ` Christoph Hellwig 2026-05-27 14:13 ` Cunlong Li 2026-05-27 4:49 ` [PATCH v2 2/2] zram: drop unused bio parameter from write helpers Cunlong Li 2026-05-27 7:24 ` Christoph Hellwig 2026-05-27 7:21 ` [PATCH v2 0/2] zram: fix UAF in zram_bvec_write_partial() and drop dead bio plumbing Sergey Senozhatsky 2026-05-27 14:15 ` Cunlong Li
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox