From: Mario Limonciello <mario.limonciello@dell.com>
To: Keith Busch <kbusch@kernel.org>
Cc: Sagi Grimberg <sagi@grimberg.me>,
Mario Limonciello <mario.limonciello@dell.com>,
campello@google.com, Richard Hughes <hughsient@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-nvme@lists.infradead.org, Jens Axboe <axboe@fb.com>,
jorgelo@chromium.org, Christoph Hellwig <hch@lst.de>
Subject: [RFC 2/2] nvme: Use CAP_FIRMWARE_UPGRADE to check user commands
Date: Thu, 18 Feb 2021 11:09:47 -0600 [thread overview]
Message-ID: <20210218170947.15727-3-mario.limonciello@dell.com> (raw)
In-Reply-To: <20210218170947.15727-1-mario.limonciello@dell.com>
Software that is running with CAP_FIRMWARE_UPGRADE needs a limited
set of opcode access:
* Identify the disk
* Download firmware to the disk
* Commit the firmwware to the disk
Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
drivers/nvme/host/core.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f13eb4ded95f..80be3d6b7437 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1593,13 +1593,23 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
u64 result;
int status;
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
return -EFAULT;
if (cmd.flags)
return -EINVAL;
+ switch (cmd.opcode) {
+ case nvme_admin_identify:
+ case nvme_admin_activate_fw:
+ case nvme_admin_download_fw:
+ if (!firmware_upgrade_capable())
+ return -EACCES;
+ break;
+ default:
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
+ }
+
memset(&c, 0, sizeof(c));
c.common.opcode = cmd.opcode;
c.common.flags = cmd.flags;
@@ -1637,13 +1647,23 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
unsigned timeout = 0;
int status;
- if (!capable(CAP_SYS_ADMIN))
- return -EACCES;
if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
return -EFAULT;
if (cmd.flags)
return -EINVAL;
+ switch (cmd.opcode) {
+ case nvme_admin_identify:
+ case nvme_admin_activate_fw:
+ case nvme_admin_download_fw:
+ if (!firmware_upgrade_capable())
+ return -EACCES;
+ break;
+ default:
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
+ }
+
memset(&c, 0, sizeof(c));
c.common.opcode = cmd.opcode;
c.common.flags = cmd.flags;
--
2.25.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-02-18 17:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-18 17:09 [RFC 0/2] Split out firmware upgrade from CAP_SYS_ADMIN Mario Limonciello
2021-02-18 17:09 ` [RFC 1/2] capability: Introduce CAP_FIRMWARE_UPGRADE Mario Limonciello
2021-02-18 17:09 ` Mario Limonciello [this message]
2021-07-23 0:59 ` [RFC 0/2] Split out firmware upgrade from CAP_SYS_ADMIN Daniil Lunev
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=20210218170947.15727-3-mario.limonciello@dell.com \
--to=mario.limonciello@dell.com \
--cc=axboe@fb.com \
--cc=campello@google.com \
--cc=hch@lst.de \
--cc=hughsient@gmail.com \
--cc=jorgelo@chromium.org \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).