* [PATCH v3] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
@ 2021-04-02 20:18 Niklas Cassel
2021-04-03 8:15 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Niklas Cassel @ 2021-04-02 20:18 UTC (permalink / raw)
To: kbusch, axboe, hch, sagi
Cc: niklas.cassel, joshi.k, javier, 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>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Javier González <javier@javigon.com>
---
Changes since v2:
-Picked up Reviewed-by-tags.
-Send from a mail server that doesn't mangle the mail.
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev
2021-04-02 20:18 [PATCH v3] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev Niklas Cassel
@ 2021-04-03 8:15 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2021-04-03 8:15 UTC (permalink / raw)
To: Niklas Cassel
Cc: kbusch, axboe, hch, sagi, niklas.cassel, joshi.k, javier,
linux-nvme, linux-kernel
So it turns out that while git-am complained it did apply the patch
just fine and it didn't look whitespace mangled. No idea what went
on there, but the patch is in nvme-5.13 now.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-03 8:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02 20:18 [PATCH v3] nvme: disallow passthru cmd from targeting a nsid != nsid of the block dev Niklas Cassel
2021-04-03 8:15 ` 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).