nvme: restrict management ioctls to admin
authorKeith Busch <kbusch@kernel.org>
Thu, 22 Sep 2022 14:54:06 +0000 (07:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Dec 2022 10:23:05 +0000 (11:23 +0100)
commit c0393ef282ed49a7c8955a6f12e9803773568b84 upstream.

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.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
drivers/nvme/host/core.c

index 6627fb531f336a8469e1a0aaa3b88cb3c8bd67e2..3b5e5fb158be2ca1666a64f64de98970efdaeafa 100644 (file)
@@ -3027,11 +3027,17 @@ static 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: