Skip to content

Commit 5a4b653

Browse files
Ming Leiaxboe
authored andcommitted
zram: avoid race between zram_remove and disksize_store
After resetting device in zram_remove(), disksize_store still may come and allocate resources again before deleting gendisk, fix the race by resetting zram after del_gendisk() returns. At that time, disksize_store can't come any more. 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 8c54499 commit 5a4b653

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,13 @@ static int zram_remove(struct zram *zram)
20062006
/* del_gendisk drains pending reset_store */
20072007
WARN_ON_ONCE(claimed && zram->claim);
20082008

2009+
/*
2010+
* disksize_store() may be called in between zram_reset_device()
2011+
* and del_gendisk(), so run the last reset to avoid leaking
2012+
* anything allocated with disksize_store()
2013+
*/
2014+
zram_reset_device(zram);
2015+
20092016
blk_cleanup_disk(zram->disk);
20102017
kfree(zram);
20112018
return 0;

0 commit comments

Comments
 (0)