Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: jsmart2021@gmail.com (jsmart2021@gmail.com)
Subject: [PATCH] nvmet core: skip flags checks on fabric commands
Date: Thu, 27 Apr 2017 17:20:56 -0700	[thread overview]
Message-ID: <20170428002056.26213-1-jsmart2021@gmail.com> (raw)

From: James Smart <jsmart2021@gmail.com>

The core layer validates nvme command flags (w0 byte 1) values before
decoding opcodes. On fabric commands the flags field is reserved.
Current validations require NVME_CMD_SGL_METABUF or NVME_CMD_SGL_METASEG
to be set. If host sets flags to 0 as reserved field, command fails.

Exclude fabric commands from flags checks.

Signed-off-by: James Smart <james.smart at broadcom.com>
---
 drivers/nvme/target/core.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index cf90713..2ad987a 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -475,6 +475,20 @@ int nvmet_sq_init(struct nvmet_sq *sq)
 }
 EXPORT_SYMBOL_GPL(nvmet_sq_init);
 
+u16 nvmet_req_validate_flags(u8 flags)
+{
+	/* no support for fused commands yet */
+	if (unlikely(flags & (NVME_CMD_FUSE_FIRST | NVME_CMD_FUSE_SECOND)))
+		return (NVME_SC_INVALID_FIELD | NVME_SC_DNR);
+
+	/* either variant of SGLs is fine, as we don't support metadata */
+	if (unlikely((flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METABUF &&
+		     (flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METASEG))
+		return (NVME_SC_INVALID_FIELD | NVME_SC_DNR);
+
+	return 0;
+}
+
 bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
 		struct nvmet_sq *sq, struct nvmet_fabrics_ops *ops)
 {
@@ -488,17 +502,11 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
 	req->sg_cnt = 0;
 	req->rsp->status = 0;
 
-	/* no support for fused commands yet */
-	if (unlikely(flags & (NVME_CMD_FUSE_FIRST | NVME_CMD_FUSE_SECOND))) {
-		status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
-		goto fail;
-	}
-
-	/* either variant of SGLs is fine, as we don't support metadata */
-	if (unlikely((flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METABUF &&
-		     (flags & NVME_CMD_SGL_ALL) != NVME_CMD_SGL_METASEG)) {
-		status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
-		goto fail;
+	/* validate flags except on fabric commands, where field is rsvd */
+	if (req->cmd->common.opcode != nvme_fabrics_command) {
+		status = nvmet_req_validate_flags(flags);
+		if (status)
+			goto fail;
 	}
 
 	if (unlikely(!req->sq->ctrl))
-- 
2.9.3

             reply	other threads:[~2017-04-28  0:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-28  0:20 jsmart2021 [this message]
2017-04-28  3:03 ` [PATCH] nvmet core: skip flags checks on fabric commands James Smart

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=20170428002056.26213-1-jsmart2021@gmail.com \
    --to=jsmart2021@gmail.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