From: zhongjinghua <zhongjinghua@huawei.com>
To: Bart Van Assche <bvanassche@acm.org>,
Zhong Jinghua <zhongjinghua@huaweicloud.com>,
<jejb@linux.ibm.com>, <martin.petersen@oracle.com>
Cc: <linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yi.zhang@huawei.com>, <yukuai3@huawei.com>
Subject: Re: [PATCH-next] scsi: fix use-after-free problem in scsi_remove_target
Date: Mon, 6 Mar 2023 16:29:16 +0800 [thread overview]
Message-ID: <02189eaa-1964-3fa6-6a06-16d248a3d80d@huawei.com> (raw)
In-Reply-To: <5cf19e69-b851-abe9-9496-bbba33109404@acm.org>
在 2023/3/2 3:46, Bart Van Assche 写道:
> On 2/12/23 19:43, Zhong Jinghua wrote:
>> T0 T1
>> sdev_store_delete
>> scsi_remove_device
>> device_remove_file
>> __scsi_remove_device
>> __iscsi_unbind_session
>> scsi_remove_target
>> spin_lock_irqsave
>> list_for_each_entry
>> scsi_target_reap // starget->reaf 1 -> 0
>
> What is "reaf"? Did you perhaps want to write "reap_ref"?
Yes, I will modify late.
>
>> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
>> index e7893835b99a..0ad357ff4c59 100644
>> --- a/drivers/scsi/scsi_sysfs.c
>> +++ b/drivers/scsi/scsi_sysfs.c
>> @@ -1561,7 +1561,17 @@ void scsi_remove_target(struct device *dev)
>> starget->state == STARGET_CREATED_REMOVE)
>> continue;
>> if (starget->dev.parent == dev || &starget->dev == dev) {
>> - kref_get(&starget->reap_ref);
>> +
>> + /*
>> + * If starget->reap_ref is reduced to 0, it means
>> + * that other processes are releasing it and
>> + * there is no need to delete it again
>> + */
>> + if (!kref_get_unless_zero(&starget->reap_ref)) {
>> + spin_unlock_irqrestore(shost->host_lock, flags);
>> + goto restart;
>> + }
>> +
>> if (starget->state == STARGET_CREATED)
>> starget->state = STARGET_CREATED_REMOVE;
>> else
>
> The above comment should be made more clear, e.g. as follows: "If the
> reference count is already zero, skip this target. Calling
> kref_get_unless_zero() if the reference count is zero is safe because
> scsi_target_destroy() will wait until the host lock has been released
> before freeing starget."
Agree. Thanks for your e.g.
I will send the v2 late.
>
> Otherwise this patch looks fine to me.
>
> Thanks,
>
> Bart.
>
>
Thanks,
Jinghua
prev parent reply other threads:[~2023-03-06 8:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 3:43 [PATCH-next] scsi: fix use-after-free problem in scsi_remove_target Zhong Jinghua
2023-03-01 3:37 ` zhongjinghua
2023-03-01 3:40 ` zhongjinghua
2023-03-01 19:51 ` James Bottomley
2023-03-02 8:56 ` zhongjinghua
2023-03-01 21:15 ` Mike Christie
2023-03-02 16:38 ` Mike Christie
2023-03-01 19:46 ` Bart Van Assche
2023-03-06 8:29 ` zhongjinghua [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=02189eaa-1964-3fa6-6a06-16d248a3d80d@huawei.com \
--to=zhongjinghua@huawei.com \
--cc=bvanassche@acm.org \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@huawei.com \
--cc=zhongjinghua@huaweicloud.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