From: "javier@javigon.com" <javier@javigon.com>
To: Niklas Cassel <Niklas.Cassel@wdc.com>
Cc: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@fb.com>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
"minwoo.im.dev@gmail.com" <minwoo.im.dev@gmail.com>,
"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
Date: Sat, 27 Mar 2021 08:51:45 +0100 [thread overview]
Message-ID: <20210327075145.ecbjov5prhq2vjh7@mpHalley.local> (raw)
In-Reply-To: <20210326194749.396599-1-Niklas.Cassel@wdc.com>
On 26.03.2021 19:48, Niklas Cassel wrote:
>From: Niklas Cassel <niklas.cassel@wdc.com>
>
>When a passthru command targets a specific namespace, the ns parameter to
>nvme_user_cmd()/nvme_user_cmd64() is set. However, there is currently no
>validation that the nsid specified in the passthru command targets the
>namespace/nsid represented by the block device that the ioctl was
>performed on.
>
>Add a check that validates that the nsid in the passthru command matches
>that of the supplied namespace.
>
>Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
>---
>Changes since v1:
>-Added error print.
>
> drivers/nvme/host/core.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
>diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>index f13eb4ded95f..a50352ea3f7b 100644
>--- a/drivers/nvme/host/core.c
>+++ b/drivers/nvme/host/core.c
>@@ -1599,6 +1599,12 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> return -EFAULT;
> if (cmd.flags)
> return -EINVAL;
>+ if (ns && cmd.nsid != ns->head->ns_id) {
>+ dev_err(ctrl->device,
>+ "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
>+ current->comm, cmd.nsid, ns->head->ns_id);
>+ return -EINVAL;
>+ }
>
> memset(&c, 0, sizeof(c));
> c.common.opcode = cmd.opcode;
>@@ -1643,6 +1649,12 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> return -EFAULT;
> if (cmd.flags)
> return -EINVAL;
>+ if (ns && cmd.nsid != ns->head->ns_id) {
>+ dev_err(ctrl->device,
>+ "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
>+ current->comm, cmd.nsid, ns->head->ns_id);
>+ return -EINVAL;
>+ }
>
> memset(&c, 0, sizeof(c));
> c.common.opcode = cmd.opcode;
>--
>2.30.2
Looks good to me
Reviewed-by: Javier González <javier@javigon.com>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-03-27 7:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-26 19:48 [PATCH v2] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev Niklas Cassel
2021-03-26 20:59 ` Sagi Grimberg
2021-03-27 7:51 ` javier [this message]
2021-04-02 16:43 ` 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=20210327075145.ecbjov5prhq2vjh7@mpHalley.local \
--to=javier@javigon.com \
--cc=Niklas.Cassel@wdc.com \
--cc=axboe@fb.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=minwoo.im.dev@gmail.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