zram: fix use-after-free in zram_bvec_write_partial()
Subsystems (3)
PATCH 1/1 zram: fix use-after-free in zram_bvec_write_partial()
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.
--- drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/zram/zram_drv.c +1 -1
@@ -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);
---
base-commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7
change-id: 20260526-zram-b01425b7e6c6
Best regards,
Signature · 1 line
Cunlong Li <[email protected]>
Sergey Senozhatsky
maintainerQuoted 25 lines · Cunlong Li
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 forZRAM_WBslots the read is dispatched asynchronously andzram_read_page()returns 0 while the bio is still in flight. The caller then runsmemcpy_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 commit4e3c87b9421d("zram: fix synchronous reads") for the same reason; thewrite_partialcounterpart was missed.Fixes 4e3c87b9421d ("zram: fix synchronous reads")Cc Christoph Hellwig <[email protected]>Signed-off-by Cunlong Li <[email protected]>--- drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/zram/zram_drv.c +0
-0
drivers/block/zram/zram_drv.c static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec, · line 2336
Quoted 5 lines
drivers/block/zram/zram_drv.c +1
-1@@ -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 );
Sounds like zram_bvec_write_partial() doesn't need bio parameter then?
Quoted 29 lines · Sergey Senozhatsky
Quoted 28 lines · Cunlong Li
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 forZRAM_WBslots the read is dispatched asynchronously andzram_read_page()returns 0 while the bio is still in flight. The caller then runsmemcpy_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 commit4e3c87b9421d("zram: fix synchronous reads") for the same reason; thewrite_partialcounterpart was missed.Fixes 4e3c87b9421d ("zram: fix synchronous reads")Cc Christoph Hellwig <[email protected]>Signed-off-by Cunlong Li <[email protected]>--- drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/block/zram/zram_drv.c +0
-0@@ -2333,7 +2333,7 @@ static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec,if (!page)return -ENOMEM ;
Quoted 4 lines
drivers/block/zram/zram_drv.c static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec, · line 2336
Quoted 2 lines
drivers/block/zram/zram_drv.c +1
-1- ret =zram_read_page (zram, page, index, bio); + ret =zram_read_page (zram, page, index,NULL );Sounds like
zram_bvec_write_partial()doesn't need bio parameter then?
Right -- v2 follows up with a cleanup patch that drops the bio parameter from both zram_bvec_write_partial() and zram_bvec_write().
Will send v2 shortly.
Thanks,
Cunlong