From: Bart Van Assche <bvanassche@acm.org>
To: Sagi Grimberg <sagi@grimberg.me>, Keith Busch <kbusch@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>,
linux-nvme@lists.infradead.org, stable@vger.kernel.org
Subject: Re: [PATCH] nvmet: Fix a use-after-free
Date: Sun, 14 Aug 2022 07:24:51 -0700 [thread overview]
Message-ID: <9ec2e292-1e75-8ee2-a9fc-d5adfab92fbd@acm.org> (raw)
In-Reply-To: <cd2189da-59b3-c01e-9bd3-5f838258c7bc@grimberg.me>
On 8/14/22 04:45, Sagi Grimberg wrote:
> On 8/13/22 00:03, Bart Van Assche wrote:
>> @@ -745,9 +747,9 @@ static void __nvmet_req_complete(struct nvmet_req
>> *req, u16 status)
>> trace_nvmet_req_complete(req);
>> - if (req->ns)
>> - nvmet_put_namespace(req->ns);
>> req->ops->queue_response(req);
>> + if (ns)
>> + nvmet_put_namespace(ns);
>
> Why did the put change position?
> I'm not exactly clear what was used-after-free here..
Hi Sagi,
Is my understanding correct that the NVMe target namespace owns the
block device `req` is associated with and hence that the namespace
reference count must only be dropped after dereferencing the `req`
pointer has finished?
This is what I found in the NVMe target code:
* nvmet_put_namespace() decreases ns->ref.
* Dropping the last ns->ref causes nvmet_destroy_namespace() to be
called. That function completes ns->disable_done.
* nvmet_ns_disable() waits on that completion and calls
nvmet_ns_dev_disable().
* For a block device, nvmet_ns_dev_disable() calls blkdev_put().
* The last blkdev_put() call calls disk_release().
* disk_release() calls blk_put_queue().
* The last blk_put_queue() call calls blk_release_queue().
* blk_release_queue() frees struct request_queue.
* blk_mq_complete_request_remote() dereferences req->q.
Thanks,
Bart.
next prev parent reply other threads:[~2022-08-14 14:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 21:03 [PATCH] nvmet: Fix a use-after-free Bart Van Assche
2022-08-14 11:45 ` Sagi Grimberg
2022-08-14 14:24 ` Bart Van Assche [this message]
2022-08-17 10:09 ` Sagi Grimberg
2022-08-17 10:17 ` Sagi Grimberg
2022-09-05 13:03 ` Christoph Hellwig
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=9ec2e292-1e75-8ee2-a9fc-d5adfab92fbd@acm.org \
--to=bvanassche@acm.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=stable@vger.kernel.org \
/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