Skip to contentSkip to conversation

nvme: restrict management ioctls to admin

PATCH Applied Keith Busch 2 participants 2 messages Sep 22, 2022 – Sep 27, 2022 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 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, which include resets and rescans, can be disruptive.

---
v1->v2:
Check the user's capability in each case individually.

 drivers/nvme/host/ioctl.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/nvme/host/ioctl.c +6 -0
index d3281f87cd6e..a48a79ed5c4c 100644
@@ -764,11 +764,17 @@ long nvme_dev_ioctl(struct file *file, unsigned int cmd,
 	case NVME_IOCTL_IO_CMD:
 		return nvme_dev_user_cmd(ctrl, argp);
 	case NVME_IOCTL_RESET:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
 		dev_warn(ctrl->device, "resetting controller\n");
 		return nvme_reset_ctrl_sync(ctrl);
 	case NVME_IOCTL_SUBSYS_RESET:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
 		return nvme_reset_subsystem(ctrl);
 	case NVME_IOCTL_RESCAN:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
 		nvme_queue_scan(ctrl);
 		return 0;
 	default:
Signature · 1 line
2.30.2