From: Li Nan <linan666@huaweicloud.com>
To: Zhihao Cheng <chengzhihao1@huawei.com>,
richard@nod.at, miquel.raynal@bootlin.com, vigneshr@ti.com,
axboe@kernel.dk, chaitanya.kulkarni@wdc.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com,
yangerkun@huawei.com
Subject: Re: [PATCH] ubi: block: fix null-pointer-dereference in ubiblock_create()
Date: Mon, 6 May 2024 21:35:22 +0800 [thread overview]
Message-ID: <9bad9355-5b5a-de61-8c53-6e65ed3332b1@huaweicloud.com> (raw)
In-Reply-To: <98698009-e3a2-5c00-7619-6b6e3422cd1b@huawei.com>
在 2024/4/28 15:51, Zhihao Cheng 写道:
> 在 2024/4/28 15:19, linan666@huaweicloud.com 写道:
>> From: Li Nan <linan122@huawei.com>
>>
>> Similar to commit adbf4c4954e3 ("ubi: block: fix memleak in
>> ubiblock_create()"), 'dev->gd' is not assigned but dereferenced if
>> blk_mq_alloc_tag_set() fails, and leading to a null-pointer-dereference.
>>
>> Using 'gd' directly here is not a good idea, too. 'gd->part0.bd_device'
>> is not initialized at this point. The error log will be:
>> block (null): block: dynamic minor allocation failed
>>
>> Fix it by using pr_err() and print ubi id.
>>
>> Fixes: 77567b25ab9f ("ubi: use blk_mq_alloc_disk and blk_cleanup_disk")
>> Signed-off-by: Li Nan <linan122@huawei.com>
>> ---
>> drivers/mtd/ubi/block.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
>> index f82e3423acb9..bf7308e8ec2f 100644
>> --- a/drivers/mtd/ubi/block.c
>> +++ b/drivers/mtd/ubi/block.c
>> @@ -390,7 +390,8 @@ int ubiblock_create(struct ubi_volume_info *vi)
>> ret = blk_mq_alloc_tag_set(&dev->tag_set);
>> if (ret) {
>> - dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed");
>> + pr_err("ubiblock%d_%d: blk_mq_alloc_tag_set failed\n",
>> + dev->ubi_num, dev->vol_id);
>> goto out_free_dev;
>> }
>> @@ -407,8 +408,8 @@ int ubiblock_create(struct ubi_volume_info *vi)
>> gd->minors = 1;
>> gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0,
>> GFP_KERNEL);
>
> There is no need to modify this place. The device of 'gd' is initialized in
> blk_mq_alloc_disk. Refer to nbd_dev_add.
The print of this dev_err() is:
block (null): block: dynamic minor allocation failed
~~~~~~
There is no information about which device failed. dev_err()
use 'kobject_name(&dev->kobj)' here, which is init in device_add_disk()
later. So use pr_err() here can print more detail.
I will split the patch into two in v2 to make it clearer.
>> if (gd->first_minor < 0) {
>> - dev_err(disk_to_dev(gd),
>> - "block: dynamic minor allocation failed");
>> + pr_err("ubiblock%d_%d: block: dynamic minor allocation failed\n",
>> + dev->ubi_num, dev->vol_id);
>> ret = -ENODEV;
>> goto out_cleanup_disk;
>> }
>>
--
Thanks,
Nan
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2024-05-06 13:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 7:19 [PATCH] ubi: block: fix null-pointer-dereference in ubiblock_create() linan666
2024-04-28 7:51 ` Zhihao Cheng
2024-05-06 13:35 ` Li Nan [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-12-08 7:13 linan666
2023-12-08 7:29 ` Zhihao Cheng
2023-12-08 7:40 ` Li Nan
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=9bad9355-5b5a-de61-8c53-6e65ed3332b1@huaweicloud.com \
--to=linan666@huaweicloud.com \
--cc=axboe@kernel.dk \
--cc=chaitanya.kulkarni@wdc.com \
--cc=chengzhihao1@huawei.com \
--cc=houtao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@huawei.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 read-only IMAP folder(s) and NNTP newsgroup(s).