Skip to contentSkip to conversation

nvme: restrict management ioctls to admin

PATCH Superseded Keith Busch 5 participants 5 messages Sep 8, 2022 – Sep 12, 2022 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: restrict management ioctls to admin

From: Keith Busch <[email protected]>

The passthrough commands already have this restriction, but the other operations do not. Require the same capabilities for all users as all of these operations can be disruptive.

---
 drivers/nvme/host/ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nvme/host/ioctl.c +3 -0
index 27614bee7380..d23978e993c6 100644
@@ -749,6 +749,9 @@ long nvme_dev_ioctl(struct file *file, unsigned int cmd,
 	struct nvme_ctrl *ctrl = file->private_data;
 	void __user *argp = (void __user *)arg;
 
+	if (!capable(CAP_SYS_ADMIN))
+		return -EACCES;
+
 	switch (cmd) {
 	case NVME_IOCTL_ADMIN_CMD:
 		return nvme_user_cmd(ctrl, NULL, argp);
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Keith Busch

From: Keith Busch <[email protected]>

The passthrough commands already have this restriction, but the other operations do not. Require the same capabilities for all users as all of these operations can be disruptive.

---
drivers/nvme/host/ioctl.c | 3 +++

1 file changed, 3 insertions(+)
drivers/nvme/host/ioctl.c +0 -0
index 27614bee7380..d23978e993c6 100644

drivers/nvme/host/ioctl.c long nvme_dev_ioctl(struct file *file, unsigned int cmd, · line 754

Quoted 6 lines
drivers/nvme/host/ioctl.c +3 -0
@@ -749,6 +749,9 @@ long nvme_dev_ioctl(struct file *file, unsigned int cmd,
 	struct nvme_ctrl *ctrl = file->private_data;
 	void __user *argp = (void __user *)arg;
 
+	if (!capable(CAP_SYS_ADMIN))
+		return -EACCES;
+

I too came across this and wondered why this check is not present here.

It's a different matter that I was looking at increasing the access granularity (something like scsi whitelisting). Hope to have conversations on a RFC soon.

Quoted 2 lines
maintainer
#2 lore raw
In reply to Keith Busch
Quoted 5 lines · Keith Busch

From: Keith Busch <[email protected]>

The passthrough commands already have this restriction, but the other operations do not. Require the same capabilities for all users as all of these operations can be disruptive.

Would it be saner to require that you have write permissions on the opened device? Not sure this CAP_SYS_ADMIN is really necessary, and might break existing setups as this is new.

I do agree that passthrough and sync ioctl based issue should be consistent, though.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Keith Busch
Quoted 5 lines · Keith Busch

From: Keith Busch <[email protected]>

The passthrough commands already have this restriction, but the other operations do not. Require the same capabilities for all users as all of these operations can be disruptive.

Where "these operations" are: NVME_IOCTL_RESET, NVME_IOCTL_SUBSYS_RESET, NVME_IOCTL_RESCAN. Yes, I think those are very disruptive and the definition of what CAP_SYS_ADMIN was designed for, but that should be spelled out in the commit log.

That being said I think we should just do the capable() check in the individul ioctl opcode to document things better, even if that does't currently make any difference. Any we really need a FIXES tag going back to the addition of the first of these ioctls.

maintainer
#4 lore raw
Quoted 5 lines
Quoted 4 lines

The passthrough commands already have this restriction, but the other operations do not. Require the same capabilities for all users as all of these operations can be disruptive.

Quoted 8 lines

Where "these operations" are: NVME_IOCTL_RESET, NVME_IOCTL_SUBSYS_RESET, NVME_IOCTL_RESCAN. Yes, I think those are very disruptive and the definition of what CAP_SYS_ADMIN was designed for, but that should be spelled out in the commit log.

That being said I think we should just do the capable() check in the individul ioctl opcode to document things better, even if that does't currently make any difference.

Agree.

Quoted 2 lines

Any we really need a FIXES tag going
back to the addition of the first of these ioctls.

100% agree on the fixes tag