Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

zram: fix uninitialized ZRAM not releasing backing device

Setting backing device is done before ZRAM initialization. If we set the
backing device, then remove the ZRAM module without initializing the
device, the backing device reference will be leaked and the device will be
hold forever.

Fix this by always reset the ZRAM fully on rmmod or reset store.

Link: https://lkml.kernel.org/r/20241209165717.94215-3-ryncsn@gmail.com
Fixes: 013bf95a83ec ("zram: add interface to specif backing device")
Signed-off-by: Kairui Song <kasong@tencent.com>
Reported-by: Desheng Wu <deshengwu@tencent.com>
Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
74363ec6 be48c412

+4 -5
+4 -5
drivers/block/zram/zram_drv.c
··· 1444 1444 size_t num_pages = disksize >> PAGE_SHIFT; 1445 1445 size_t index; 1446 1446 1447 + if (!zram->table) 1448 + return; 1449 + 1447 1450 /* Free all pages that are still in this zram device */ 1448 1451 for (index = 0; index < num_pages; index++) 1449 1452 zram_free_page(zram, index); 1450 1453 1451 1454 zs_destroy_pool(zram->mem_pool); 1452 1455 vfree(zram->table); 1456 + zram->table = NULL; 1453 1457 } 1454 1458 1455 1459 static bool zram_meta_alloc(struct zram *zram, u64 disksize) ··· 2329 2325 down_write(&zram->init_lock); 2330 2326 2331 2327 zram->limit_pages = 0; 2332 - 2333 - if (!init_done(zram)) { 2334 - up_write(&zram->init_lock); 2335 - return; 2336 - } 2337 2328 2338 2329 set_capacity_and_notify(zram->disk, 0); 2339 2330 part_stat_set_all(zram->disk->part0, 0);