diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2017-03-27 19:12:43 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-04-21 03:31:21 -0400 |
commit | 92f8aa7bb825eafc3686cdda6dbbce44d8b35e75 (patch) | |
tree | 90df925eeaf5d255e7dc450a85f43b1ee8583c3b | |
parent | 08383b004426591502b86bfacdc638d85cedf26c (diff) |
target: Avoid mappedlun symlink creation during lun shutdown
commit 49cb77e297dc611a1b795cfeb79452b3002bd331 upstream.
This patch closes a race between se_lun deletion during configfs
unlink in target_fabric_port_unlink() -> core_dev_del_lun()
-> core_tpg_remove_lun(), when transport_clear_lun_ref() blocks
waiting for percpu_ref RCU grace period to finish, but a new
NodeACL mappedlun is added before the RCU grace period has
completed.
This can happen in target_fabric_mappedlun_link() because it
only checks for se_lun->lun_se_dev, which is not cleared until
after transport_clear_lun_ref() percpu_ref RCU grace period
finishes.
This bug originally manifested as NULL pointer dereference
OOPsen in target_stat_scsi_att_intr_port_show_attr_dev() on
v4.1.y code, because it dereferences lun->lun_se_dev without
a explicit NULL pointer check.
In post v4.1 code with target-core RCU conversion, the code
in target_stat_scsi_att_intr_port_show_attr_dev() no longer
uses se_lun->lun_se_dev, but the same race still exists.
To address the bug, go ahead and set se_lun>lun_shutdown as
early as possible in core_tpg_remove_lun(), and ensure new
NodeACL mappedlun creation in target_fabric_mappedlun_link()
fails during se_lun shutdown.
Reported-by: James Shen <jcs@datera.io>
Cc: James Shen <jcs@datera.io>
Tested-by: James Shen <jcs@datera.io>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/target/target_core_fabric_configfs.c | 5 | ||||
-rw-r--r-- | drivers/target/target_core_tpg.c | 4 | ||||
-rw-r--r-- | include/target/target_core_base.h | 1 |
3 files changed, 10 insertions, 0 deletions
diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c index 31a096aa16ab..6e456de5e564 100644 --- a/drivers/target/target_core_fabric_configfs.c +++ b/drivers/target/target_core_fabric_configfs.c | |||
@@ -92,6 +92,11 @@ static int target_fabric_mappedlun_link( | |||
92 | pr_err("Source se_lun->lun_se_dev does not exist\n"); | 92 | pr_err("Source se_lun->lun_se_dev does not exist\n"); |
93 | return -EINVAL; | 93 | return -EINVAL; |
94 | } | 94 | } |
95 | if (lun->lun_shutdown) { | ||
96 | pr_err("Unable to create mappedlun symlink because" | ||
97 | " lun->lun_shutdown=true\n"); | ||
98 | return -EINVAL; | ||
99 | } | ||
95 | se_tpg = lun->lun_tpg; | 100 | se_tpg = lun->lun_tpg; |
96 | 101 | ||
97 | nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item; | 102 | nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item; |
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 2744251178ad..1949f50725a5 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c | |||
@@ -640,6 +640,8 @@ void core_tpg_remove_lun( | |||
640 | */ | 640 | */ |
641 | struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); | 641 | struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); |
642 | 642 | ||
643 | lun->lun_shutdown = true; | ||
644 | |||
643 | core_clear_lun_from_tpg(lun, tpg); | 645 | core_clear_lun_from_tpg(lun, tpg); |
644 | /* | 646 | /* |
645 | * Wait for any active I/O references to percpu se_lun->lun_ref to | 647 | * Wait for any active I/O references to percpu se_lun->lun_ref to |
@@ -661,6 +663,8 @@ void core_tpg_remove_lun( | |||
661 | } | 663 | } |
662 | if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) | 664 | if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) |
663 | hlist_del_rcu(&lun->link); | 665 | hlist_del_rcu(&lun->link); |
666 | |||
667 | lun->lun_shutdown = false; | ||
664 | mutex_unlock(&tpg->tpg_lun_mutex); | 668 | mutex_unlock(&tpg->tpg_lun_mutex); |
665 | 669 | ||
666 | percpu_ref_exit(&lun->lun_ref); | 670 | percpu_ref_exit(&lun->lun_ref); |
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 6233e8fd95b5..0383c601e17c 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h | |||
@@ -705,6 +705,7 @@ struct se_lun { | |||
705 | u64 unpacked_lun; | 705 | u64 unpacked_lun; |
706 | #define SE_LUN_LINK_MAGIC 0xffff7771 | 706 | #define SE_LUN_LINK_MAGIC 0xffff7771 |
707 | u32 lun_link_magic; | 707 | u32 lun_link_magic; |
708 | bool lun_shutdown; | ||
708 | bool lun_access_ro; | 709 | bool lun_access_ro; |
709 | u32 lun_index; | 710 | u32 lun_index; |
710 | 711 | ||