Browse Source

scsi: tcmu: check if dev is configured before block/reset

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>
Mike Christie 7 years ago
parent
commit
a30b0473b6
1 changed files with 10 additions and 0 deletions
  1. 10 0
      drivers/target/target_core_user.c

+ 10 - 0
drivers/target/target_core_user.c

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