Skip to content

Commit 5378c92

Browse files
Yunlongsgregkh
authored andcommitted
drivers/block/null_blk/main: Fix a double free in null_init.
[ Upstream commit 72ce11d ] In null_init, null_add_dev(dev) is called. In null_add_dev, it calls null_free_zoned_dev(dev) to free dev->zones via kvfree(dev->zones) in out_cleanup_zone branch and returns err. Then null_init accept the err code and then calls null_free_dev(dev). But in null_free_dev(dev), dev->zones is freed again by null_free_zoned_dev(). My patch set dev->zones to NULL in null_free_zoned_dev() after kvfree(dev->zones) is called, to avoid the double free. Fixes: 2984c86 ("nullb: factor disk parameters") Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn> Link: https://lore.kernel.org/r/20210426143229.7374-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 94f1bdf commit 5378c92

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎drivers/block/null_blk_zoned.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void null_free_zoned_dev(struct nullb_device *dev)
149149
{
150150
bitmap_free(dev->zone_locks);
151151
kvfree(dev->zones);
152+
dev->zones = NULL;
152153
}
153154

154155
static inline void null_lock_zone(struct nullb_device *dev, unsigned int zno)

0 commit comments

Comments
 (0)