Skip to content

Commit

Permalink
nvme: disallow passthru cmd from targeting a nsid != nsid of the bloc…
Browse files Browse the repository at this point in the history
…k dev

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: Javier González <javier@javigon.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Niklas Cassel authored and Christoph Hellwig committed Apr 6, 2021
1 parent dd8f7fa commit c881a23
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,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;
Expand Down Expand Up @@ -1676,6 +1682,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;
Expand Down

0 comments on commit c881a23

Please sign in to comment.