From: Zenghui Yu <yuzenghui@huawei.com>
To: Johan Hovold <johan@kernel.org>
Cc: <linux-scsi@vger.kernel.org>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <fujita.tomonori@lab.ntt.co.jp>,
<axboe@kernel.dk>, <martin.petersen@oracle.com>, <hch@lst.de>,
<gregkh@linuxfoundation.org>, <wanghaibin.wang@huawei.com>
Subject: Re: [PATCH] scsi: bsg: Fix device unregistration
Date: Sat, 11 Sep 2021 09:41:03 +0800 [thread overview]
Message-ID: <0506e034-e186-a73b-3046-6b0e1f397756@huawei.com> (raw)
In-Reply-To: <YTtTU4+DZEb4WRkR@hovoldconsulting.com>
On 2021/9/10 20:45, Johan Hovold wrote:
> On Thu, Sep 09, 2021 at 11:46:08AM +0800, Zenghui Yu wrote:
>> @@ -218,6 +226,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
>> out_device_del:
>> cdev_device_del(&bd->cdev, &bd->device);
>> out_ida_remove:
>> + put_device(&bd->device);
>> ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
>> out_kfree:
>> kfree(bd);
>
> Ehh, what about the blatant use-after-free and double-free you just
> added here?
Yeah, whoops. That's definitely wrong. I'm squash the following fix
in this patch.
Thanks for the heads up!
|diff --git a/block/bsg.c b/block/bsg.c
|index c3bb92b9af7e..882f56bff14f 100644
|--- a/block/bsg.c
|+++ b/block/bsg.c
|@@ -200,7 +200,8 @@ struct bsg_device *bsg_register_queue(struct
request_queue *q,
| if (ret < 0) {
| if (ret == -ENOSPC)
| dev_err(parent, "bsg: too many bsg devices\n");
|- goto out_kfree;
|+ kfree(bd);
|+ return ERR_PTR(ret);
| }
| bd->device.devt = MKDEV(bsg_major, ret);
| bd->device.class = bsg_class;
|@@ -213,7 +214,7 @@ struct bsg_device *bsg_register_queue(struct
request_queue *q,
| bd->cdev.owner = THIS_MODULE;
| ret = cdev_device_add(&bd->cdev, &bd->device);
| if (ret)
|- goto out_ida_remove;
|+ goto out_put_device;
|
| if (q->kobj.sd) {
| ret = sysfs_create_link(&q->kobj, &bd->device.kobj, "bsg");
|@@ -225,11 +226,8 @@ struct bsg_device *bsg_register_queue(struct
request_queue *q,
|
| out_device_del:
| cdev_device_del(&bd->cdev, &bd->device);
|-out_ida_remove:
|+out_put_device:
| put_device(&bd->device);
|- ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt));
|-out_kfree:
|- kfree(bd);
| return ERR_PTR(ret);
| }
| EXPORT_SYMBOL_GPL(bsg_register_queue);
prev parent reply other threads:[~2021-09-11 1:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 3:46 [PATCH] scsi: bsg: Fix device unregistration Zenghui Yu
2021-09-09 5:22 ` Christoph Hellwig
2021-09-09 5:36 ` Greg KH
2021-09-09 20:40 ` Jens Axboe
2021-09-09 20:42 ` Jens Axboe
2021-09-10 1:28 ` Martin K. Petersen
2021-09-10 7:38 ` Christoph Hellwig
2021-09-10 12:45 ` Johan Hovold
2021-09-10 16:50 ` Martin K. Petersen
2021-09-11 1:41 ` Zenghui Yu [this message]
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=0506e034-e186-a73b-3046-6b0e1f397756@huawei.com \
--to=yuzenghui@huawei.com \
--cc=axboe@kernel.dk \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=johan@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=wanghaibin.wang@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