From: "Nadolski, Edmund" <edmund.nadolski@intel.com>
To: Israel Rukshin <israelr@mellanox.com>,
Linux-nvme <linux-nvme@lists.infradead.org>,
Sagi Grimberg <sagi@grimberg.me>, Christoph Hellwig <hch@lst.de>
Cc: Max Gurtovoy <maxg@mellanox.com>
Subject: Re: [PATCH 2/2] nvmet: Fix controller use after free
Date: Tue, 4 Feb 2020 07:49:10 -0700 [thread overview]
Message-ID: <52af0457-128a-48dc-0a75-39ced216ba85@intel.com> (raw)
In-Reply-To: <1580819890-11455-2-git-send-email-israelr@mellanox.com>
On 2/4/2020 5:38 AM, Israel Rukshin wrote:
> After nvmet_install_queue() sets sq->ctrl calling to nvmet_sq_destroy()
> reduces the controller refcount. In case nvmet_install_queue() fails,
> calling to nvmet_ctrl_put() is done twice (at nvmet_sq_destroy and
> nvmet_execute_io_connect/nvmet_execute_admin_connect) instead of once for
> the queue which leads to use after free of the controller. Fix this by set
> NULL at sq->ctrl in case of a failure at nvmet_install_queue().
>
> The bug leads to the following Call Trace:
>
> [65857.994862] refcount_t: underflow; use-after-free.
> [65858.108304] Workqueue: events nvmet_rdma_release_queue_work [nvmet_rdma]
> [65858.115557] RIP: 0010:refcount_warn_saturate+0xe5/0xf0
> [65858.208141] Call Trace:
> [65858.211203] nvmet_sq_destroy+0xe1/0xf0 [nvmet]
> [65858.216383] nvmet_rdma_release_queue_work+0x37/0xf0 [nvmet_rdma]
> [65858.223117] process_one_work+0x167/0x370
> [65858.227776] worker_thread+0x49/0x3e0
> [65858.232089] kthread+0xf5/0x130
> [65858.235895] ? max_active_store+0x80/0x80
> [65858.240504] ? kthread_bind+0x10/0x10
> [65858.244832] ret_from_fork+0x1f/0x30
> [65858.249074] ---[ end trace f82d59250b54beb7 ]---
>
> Fixes: bb1cc74790eb ("nvmet: implement valid sqhd values in completions")
> Fixes: 1672ddb8d691 ("nvmet: Add install_queue callout")
> Signed-off-by: Israel Rukshin <israelr@mellanox.com>
> Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
> ---
> drivers/nvme/target/fabrics-cmd.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c
> index 53ef507..799de18 100644
> --- a/drivers/nvme/target/fabrics-cmd.c
> +++ b/drivers/nvme/target/fabrics-cmd.c
> @@ -109,6 +109,7 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
> u16 qid = le16_to_cpu(c->qid);
> u16 sqsize = le16_to_cpu(c->sqsize);
> struct nvmet_ctrl *old;
> + u16 ret;
>
> old = cmpxchg(&req->sq->ctrl, NULL, ctrl);
> if (old) {
> @@ -119,7 +120,8 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
> if (!sqsize) {
> pr_warn("queue size zero!\n");
> req->error_loc = offsetof(struct nvmf_connect_command, sqsize);
> - return NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
> + ret = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
> + goto err;
> }
>
> /* note: convert queue size from 0's-based value to 1's-based value */
> @@ -132,16 +134,19 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
> }
>
> if (ctrl->ops->install_queue) {
> - u16 ret = ctrl->ops->install_queue(req->sq);
> -
> + ret = ctrl->ops->install_queue(req->sq);
> if (ret) {
> pr_err("failed to install queue %d cntlid %d ret %x\n",
> qid, ctrl->cntlid, ret);
> - return ret;
> + goto err;
> }
> }
>
> return 0;
> +
> +err:
> + req->sq->ctrl = NULL;
> + return ret;
> }
>
> static void nvmet_execute_admin_connect(struct nvmet_req *req)
>
Looks good.
Ed
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2020-02-04 14:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 12:38 [PATCH 1/2] nvmet: Fix error print message at nvmet_install_queue function Israel Rukshin
2020-02-04 12:38 ` [PATCH 2/2] nvmet: Fix controller use after free Israel Rukshin
2020-02-04 14:49 ` Nadolski, Edmund [this message]
2020-02-04 16:03 ` Christoph Hellwig
2020-02-07 20:03 ` Sagi Grimberg
2020-02-04 14:48 ` [PATCH 1/2] nvmet: Fix error print message at nvmet_install_queue function Nadolski, Edmund
2020-02-04 15:59 ` Christoph Hellwig
2020-02-07 20:03 ` Sagi Grimberg
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=52af0457-128a-48dc-0a75-39ced216ba85@intel.com \
--to=edmund.nadolski@intel.com \
--cc=hch@lst.de \
--cc=israelr@mellanox.com \
--cc=linux-nvme@lists.infradead.org \
--cc=maxg@mellanox.com \
--cc=sagi@grimberg.me \
/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