linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
@ 2021-03-26 19:48 Niklas Cassel
  2021-03-26 20:59 ` Sagi Grimberg
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Niklas Cassel @ 2021-03-26 19:48 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
  Cc: minwoo.im.dev, javier, Niklas Cassel, linux-nvme, linux-kernel

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

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
  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
  2021-04-02 16:43 ` [PATCH v2] " Christoph Hellwig
  2 siblings, 0 replies; 4+ messages in thread
From: Sagi Grimberg @ 2021-03-26 20:59 UTC (permalink / raw)
  To: Niklas Cassel, Keith Busch, Jens Axboe, Christoph Hellwig
  Cc: minwoo.im.dev, javier, linux-nvme, linux-kernel

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
  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
  2021-04-02 16:43 ` [PATCH v2] " Christoph Hellwig
  2 siblings, 0 replies; 4+ messages in thread
From: javier @ 2021-03-27  7:51 UTC (permalink / raw)
  To: Niklas Cassel
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	minwoo.im.dev, linux-nvme, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
  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
@ 2021-04-02 16:43 ` Christoph Hellwig
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2021-04-02 16:43 UTC (permalink / raw)
  To: Niklas Cassel
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	minwoo.im.dev, javier, linux-nvme, linux-kernel

On Fri, Mar 26, 2021 at 07:48:00PM +0000, 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.

git-am doesn't seem to like this patch:

pplying: nvme: disallow passthru cmd from targeting a nsid != nsid of the block
dev
error: invalid mode on line 2: 100644<br>
--- a/drivers/nvme/host/core.c<br>
+++ b/drivers/nvme/host/core.c<br>
@@ -1599,6 +1599,12 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct
nvme_ns *ns,<br>
                return -EFAULT;<br>
        if (cmd.flags)<br>
                return -EINVAL;<br>
+       if (ns &amp;&amp; cmd.nsid != ns-&gt;head-&gt;ns_id) {<br>
+               dev_err(ctrl-&gt;device,<br>
+                       &quot;%s: nsid (%u) in cmd does not match nsid (%u) of
namespace\n&quot;,<br>
+                       current-&gt;comm, cmd.nsid, ns-&gt;head-&gt;ns_id);<br>
+               return -EINVAL;<br>
+       }<br>
<br>
        memset(&amp;c, 0, sizeof(c));<br>
        c.common.opcode = cmd.opcode;<br>
@@ -1643,6 +1649,12 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl,
struct nvme_ns *ns,<br>
                return -EFAULT;<br>
        if (cmd.flags)<br>
                return -EINVAL;<br>
+       if (ns &amp;&amp; cmd.nsid != ns-&gt;head-&gt;ns_id) {<br>
+               dev_err(ctrl-&gt;device,<br>
+                       &quot;%s: nsid (%u) in cmd does not match nsid (%u) of
namespace\n&quot;,<br>
+                       current-&gt;comm, cmd.nsid, ns-&gt;head-&gt;ns_id);<br>
+               return -EINVAL;<br>
+       }<br>
<br>
        memset(&amp;c, 0, sizeof(c));<br>
        c.common.opcode = cmd.opcode;<br></blockquote></div></div><div
dir="auto"><br style="font-family:sans-serif;font-size:12.8px"><span
style="font-family:sans-serif;font-size:12.8px">Looks good.</span></div><div
dir="auto"><span style="font-family:sans-serif;font-size:12.8px">Reviewed-by:
Kanchan Joshi &lt;joshi.k</span><a href="mailto:javier@javigon.com"
style="text-decoration-line:none;color:rgb(66,133,244);font-family:sans-serif;font-size:12.8px">@samsung.com</a><span
style="font-family:sans-serif;font-size:12.8px">&gt;</span><br></div><div
dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex"></blockquote></div></div></div>




_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-02 16:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-04-02 16:43 ` [PATCH v2] " Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).