public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
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>,
	"javier@javigon.com" <javier@javigon.com>,
	"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
Date: Fri, 2 Apr 2021 18:43:18 +0200	[thread overview]
Message-ID: <20210402164318.GA21840@lst.de> (raw)
In-Reply-To: <20210326194749.396599-1-Niklas.Cassel@wdc.com>

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>




      parent reply	other threads:[~2021-04-02 16:43 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
2021-04-02 16:43 ` Christoph Hellwig [this message]

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=20210402164318.GA21840@lst.de \
    --to=hch@lst.de \
    --cc=Niklas.Cassel@wdc.com \
    --cc=axboe@fb.com \
    --cc=javier@javigon.com \
    --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