From: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
To: axboe@kernel.dk, damien.lemoal@wdc.com,
johannes.thumshirn@edc.com, martin.petersen@oracle.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Subject: [PATCH] drivers/block/null_blk/main: Fix a double free in null_init.
Date: Mon, 26 Apr 2021 07:32:29 -0700 [thread overview]
Message-ID: <20210426143229.7374-1-lyl2019@mail.ustc.edu.cn> (raw)
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: 2984c8684f962 ("nullb: factor disk parameters")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
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 bfcab1c782b5..dae54dd1aeac 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -180,6 +180,7 @@ int null_register_zoned_dev(struct nullb *nullb)
void null_free_zoned_dev(struct nullb_device *dev)
{
kvfree(dev->zones);
+ dev->zones = NULL;
}
int null_report_zones(struct gendisk *disk, sector_t sector,
--
2.25.1
next reply other threads:[~2021-04-26 14:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-26 14:32 Lv Yunlong [this message]
2021-04-26 15:05 ` [PATCH] drivers/block/null_blk/main: Fix a double free in null_init Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210426143229.7374-1-lyl2019@mail.ustc.edu.cn \
--to=lyl2019@mail.ustc.edu.cn \
--cc=axboe@kernel.dk \
--cc=damien.lemoal@wdc.com \
--cc=johannes.thumshirn@edc.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).