From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 1/4] nvme: return an errno from nvme_cmd_allowed
Date: Wed, 16 Nov 2022 14:01:01 +0100 [thread overview]
Message-ID: <20221116130104.2186334-2-hch@lst.de> (raw)
In-Reply-To: <20221116130104.2186334-1-hch@lst.de>
Return an errno value instead of bool from nvme_cmd_allowed to prepare
it for returning different kinds of errors.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/ioctl.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 9550a69029b36..9a2f0f5ccef57 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -8,11 +8,11 @@
#include <linux/io_uring.h>
#include "nvme.h"
-static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
+static int nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
fmode_t mode)
{
if (capable(CAP_SYS_ADMIN))
- return true;
+ return 0;
/*
* Do not allow unprivileged processes to send vendor specific or fabrics
@@ -20,7 +20,7 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
*/
if (c->common.opcode >= nvme_cmd_vendor_start ||
c->common.opcode == nvme_fabrics_command)
- return false;
+ return -EACCES;
/*
* Do not allow unprivileged passthrough of admin commands except
@@ -34,10 +34,10 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
case NVME_ID_CNS_NS:
case NVME_ID_CNS_CS_NS:
case NVME_ID_CNS_NS_CS_INDEP:
- return true;
+ return 0;
}
}
- return false;
+ return -EACCES;
}
/*
@@ -45,9 +45,9 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
* special file is open for writing, but always allow I/O commands that
* transfer data from the controller.
*/
- if (nvme_is_write(c))
- return mode & FMODE_WRITE;
- return true;
+ if (nvme_is_write(c) && !(mode & FMODE_WRITE))
+ return -EACCES;
+ return 0;
}
/*
@@ -331,8 +331,9 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.common.cdw14 = cpu_to_le32(cmd.cdw14);
c.common.cdw15 = cpu_to_le32(cmd.cdw15);
- if (!nvme_cmd_allowed(ns, &c, mode))
- return -EACCES;
+ status = nvme_cmd_allowed(ns, &c, mode);
+ if (status)
+ return status;
if (cmd.timeout_ms)
timeout = msecs_to_jiffies(cmd.timeout_ms);
@@ -379,8 +380,9 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.common.cdw14 = cpu_to_le32(cmd.cdw14);
c.common.cdw15 = cpu_to_le32(cmd.cdw15);
- if (!nvme_cmd_allowed(ns, &c, mode))
- return -EACCES;
+ status = nvme_cmd_allowed(ns, &c, mode);
+ if (status)
+ return status;
if (cmd.timeout_ms)
timeout = msecs_to_jiffies(cmd.timeout_ms);
@@ -549,8 +551,9 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.common.cdw14 = cpu_to_le32(READ_ONCE(cmd->cdw14));
c.common.cdw15 = cpu_to_le32(READ_ONCE(cmd->cdw15));
- if (!nvme_cmd_allowed(ns, &c, ioucmd->file->f_mode))
- return -EACCES;
+ ret = nvme_cmd_allowed(ns, &c, ioucmd->file->f_mode);
+ if (ret)
+ return ret;
d.metadata = READ_ONCE(cmd->metadata);
d.addr = READ_ONCE(cmd->addr);
--
2.30.2
next prev parent reply other threads:[~2022-11-16 13:01 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20221116130636epcas5p39a586e15d27045752f18d022f4efd74a@epcas5p3.samsung.com>
2022-11-16 13:01 ` block dangerous passthrough operation Christoph Hellwig
2022-11-16 13:01 ` Christoph Hellwig [this message]
2022-11-16 13:01 ` [PATCH 2/4] nvme: don't allow user space to send fabrics commands Christoph Hellwig
2022-11-16 13:01 ` [PATCH 3/4] nvme: don't allow userspace to set the Host Behavior Support feature Christoph Hellwig
2022-11-16 13:01 ` [PATCH 4/4] nvme: reject passthrough of queue creation / deletion commands Christoph Hellwig
2022-11-16 13:25 ` block dangerous passthrough operation Kanchan Joshi
2022-11-16 13:38 ` Christoph Hellwig
2022-11-16 13:43 ` Kanchan Joshi
2022-11-16 15:44 ` Christoph Hellwig
2022-11-17 3:13 ` Kanchan Joshi
2022-11-21 7:43 ` Christoph Hellwig
2022-11-16 16:12 ` Keith Busch
2022-11-17 3:51 ` Kanchan Joshi
2022-11-17 16:03 ` Keith Busch
2022-11-17 6:48 ` Chaitanya Kulkarni
2022-11-21 7:45 ` Christoph Hellwig
2022-11-17 3:49 ` Jens Axboe
2022-11-21 7:46 ` Christoph Hellwig
2022-11-21 15:35 ` Keith Busch
2022-11-22 6:47 ` Christoph Hellwig
2022-11-22 10:38 ` Sagi Grimberg
2022-11-22 12:03 ` Christoph Hellwig
2022-11-22 15:11 ` Keith Busch
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=20221116130104.2186334-2-hch@lst.de \
--to=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--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