target: Fix alua_access_state attribute OOPs for un-configured devices
authorNicholas Bellinger <nab@linux-iscsi.org>
Fri, 6 Jun 2014 07:52:57 +0000 (00:52 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Fri, 6 Jun 2014 08:22:41 +0000 (01:22 -0700)
This patch fixes a OOPs where an attempt to write to the per-device
alua_access_state configfs attribute at:

  /sys/kernel/config/target/core/$HBA/$DEV/alua/$TG_PT_GP/alua_access_state

results in an NULL pointer dereference when the backend device has not
yet been configured.

This patch adds an explicit check for DF_CONFIGURED, and fails with
-ENODEV to avoid this case.

Reported-by: Chris Boot <crb@tiger-computing.co.uk>
Reported-by: Philip Gaw <pgaw@darktech.org.uk>
Cc: Chris Boot <crb@tiger-computing.co.uk>
Cc: Philip Gaw <pgaw@darktech.org.uk>
Cc: stable@vger.kernel.org # 3.8+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_configfs.c

index 60a9ae6df763d4928c4077ee210db39480872daa..bf55c5a04cfac68983b2c565c9f9498f6aaad1ed 100644 (file)
@@ -2227,6 +2227,11 @@ static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state(
                        " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id);
                return -EINVAL;
        }
+       if (!(dev->dev_flags & DF_CONFIGURED)) {
+               pr_err("Unable to set alua_access_state while device is"
+                      " not configured\n");
+               return -ENODEV;
+       }
 
        ret = kstrtoul(page, 0, &tmp);
        if (ret < 0) {