[lkml]   [2021]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 5.10 346/530] drivers/block/null_blk/main: Fix a double free in null_init.
From: Lv Yunlong <>

[ Upstream commit 72ce11ddfa4e9e1879103581a60b7e34547eaa0a ]

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

My patch set dev->zones to NULL in null_free_zoned_dev() after
kvfree(dev->zones) is called, to avoid the double free.

Fixes: 2984c8684f962 ("nullb: factor disk parameters")
Signed-off-by: Lv Yunlong <>
Signed-off-by: Jens Axboe <>
Signed-off-by: Sasha Levin <>
drivers/block/null_blk_zoned.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c
index 172f720b8d63..f5df82c26c16 100644
--- a/drivers/block/null_blk_zoned.c
+++ b/drivers/block/null_blk_zoned.c
@@ -149,6 +149,7 @@ void null_free_zoned_dev(struct nullb_device *dev)
+ dev->zones = NULL;

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

 \ /
  Last update: 2021-05-12 19:01    [W:1.594 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site