Skip to content
Snippets Groups Projects
Commit 5378c924 authored by Lv Yunlong's avatar Lv Yunlong Committed by Greg Kroah-Hartman
Browse files

drivers/block/null_blk/main: Fix a double free in null_init.


[ Upstream commit 72ce11dd ]

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: 2984c868 ("nullb: factor disk parameters")
Signed-off-by: default avatarLv Yunlong <lyl2019@mail.ustc.edu.cn>
Link: https://lore.kernel.org/r/20210426143229.7374-1-lyl2019@mail.ustc.edu.cn


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 94f1bdf0
No related branches found
No related tags found
No related merge requests found
...@@ -149,6 +149,7 @@ void null_free_zoned_dev(struct nullb_device *dev) ...@@ -149,6 +149,7 @@ void null_free_zoned_dev(struct nullb_device *dev)
{ {
bitmap_free(dev->zone_locks); bitmap_free(dev->zone_locks);
kvfree(dev->zones); kvfree(dev->zones);
dev->zones = NULL;
} }
static inline void null_lock_zone(struct nullb_device *dev, unsigned int zno) static inline void null_lock_zone(struct nullb_device *dev, unsigned int zno)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment