Skip to content

Commit 6f16377

Browse files
Ming Leiaxboe
authored andcommitted
zram: fix race between zram_reset_device() and disksize_store()
When the ->init_lock is released in zram_reset_device(), disksize_store() can come in and try to allocate meta, but zram_reset_device() is freeing free meta, so cause races. Link: https://lore.kernel.org/linux-block/[email protected]/T/#mc617f865a3fa2778e40f317ddf48f6447c20c073 Reported-by: Luis Chamberlain <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Signed-off-by: Ming Lei <[email protected]> Acked-by: Minchan Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 494dbee commit 6f16377

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,12 +1704,13 @@ static void zram_reset_device(struct zram *zram)
17041704
set_capacity_and_notify(zram->disk, 0);
17051705
part_stat_set_all(zram->disk->part0, 0);
17061706

1707-
up_write(&zram->init_lock);
17081707
/* I/O operation under all of CPU are done so let's free */
17091708
zram_meta_free(zram, disksize);
17101709
memset(&zram->stats, 0, sizeof(zram->stats));
17111710
zcomp_destroy(comp);
17121711
reset_bdev(zram);
1712+
1713+
up_write(&zram->init_lock);
17131714
}
17141715

17151716
static ssize_t disksize_store(struct device *dev,

0 commit comments

Comments
 (0)