]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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>
Sat, 26 Nov 2022 08:27:52 +0000 (09:27 +0100)
commit 23e085b2dead13b51fe86d27069895b740f749c0 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: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvme/host/ioctl.c

index d3281f87cd6e491ac86aef978dac9d0e8408ec4f..a48a79ed5c4c5024948a0f84b941598c8f9621ec 100644 (file)
@@ -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: