scsi: tcmu: check if dev is configured before block/reset
authorMike Christie <mchristi@redhat.com>
Mon, 23 Jul 2018 19:07:47 +0000 (14:07 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 31 Jul 2018 03:17:53 +0000 (23:17 -0400)
Do not allow userspace to block or reset the ring until the device has been
configured. This will prevent the bug where userspace can write to those
files and access mb_addr before it has been setup.

Signed-off-by: Mike Christie <mchristi@redhat.com>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/target_core_user.c

index bc8121f97d6587fe6918ed3959a8bb38bc887141..d6b402203b2046a0b198639826d2b8680dc499a4 100644 (file)
@@ -2480,6 +2480,11 @@ static ssize_t tcmu_block_dev_store(struct config_item *item, const char *page,
        u8 val;
        int ret;
 
+       if (!target_dev_configured(&udev->se_dev)) {
+               pr_err("Device is not configured.\n");
+               return -EINVAL;
+       }
+
        ret = kstrtou8(page, 0, &val);
        if (ret < 0)
                return ret;
@@ -2507,6 +2512,11 @@ static ssize_t tcmu_reset_ring_store(struct config_item *item, const char *page,
        u8 val;
        int ret;
 
+       if (!target_dev_configured(&udev->se_dev)) {
+               pr_err("Device is not configured.\n");
+               return -EINVAL;
+       }
+
        ret = kstrtou8(page, 0, &val);
        if (ret < 0)
                return ret;