Patch "target: Avoid mappedlun symlink creation during lun shutdown" has been added to the 3.18-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
target: Avoid mappedlun symlink creation during lun shutdown
to the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
target-avoid-mappedlun-symlink-creation-during-lun-shutdown.patch
and it can be found in the queue-3.18 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
49cb77e297dc611a1b795cfeb79452b3002bd331Mon Sep 17 00:00:00 2001
From: Nicholas Bellinger <[email protected]>
Date: Mon, 27 Mar 2017 16:12:43 -0700
Subject: target: Avoid mappedlun symlink creation during lun shutdown
From: Nicholas Bellinger <[email protected]>
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.
--- drivers/target/target_core_fabric_configfs.c | 5 +++++ drivers/target/target_core_tpg.c | 3 +++ include/target/target_core_base.h | 1 + 3 files changed, 9 insertions(+)
drivers/target/target_core_fabric_configfs.c +5 -0
@@ -84,6 +84,11 @@ static int target_fabric_mappedlun_link( "_tpg does not exist\n");return -EINVAL ; } +if (lun->lun_shutdown) { +pr_err ("Unable to create mappedlun symlink because" +" lun->lun_shutdown=true\n" ); +return -EINVAL ; + } se_tpg = lun->lun_sep->sep_tpg; nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item;
drivers/target/target_core_tpg.c +3 -0
@@ -843,6 +843,8 @@ void core_tpg_remove_lun(struct se_portal_group *tpg, struct se_lun *lun) { + lun->lun_shutdown = true; +core_clear_lun_from_tpg (lun, tpg);transport_clear_lun_ref (lun);
@@ -850,6 +852,7 @@ void core_tpg_remove_lun(spin_lock (&tpg->tpg_lun_lock); lun->lun_status =TRANSPORT_LUN_STATUS_FREE ; + lun->lun_shutdown = false;spin_unlock (&tpg->tpg_lun_lock);percpu_ref_exit (&lun->lun_ref);
include/target/target_core_base.h +1 -0
@@ -719,6 +719,7 @@ struct se_lun {u32 lun_access;u32 lun_flags;u32 unpacked_lun; +bool lun_shutdown;atomic_t lun_acl_count;spinlock_t lun_acl_lock;spinlock_t lun_sep_lock;
Patches currently in stable-queue which might be from [email protected] are
queue-3.18/iscsi-target-fix-delayed-logout-processing-greater-than-seconds_for_logout_comp.patch queue-3.18/iscsi-target-always-wait-for-kthread_should_stop-before-kthread-exit.patch queue-3.18/iscsi-target-fix-early-sk_data_ready-login_flags_ready-race.patch queue-3.18/iscsi-target-fix-initial-login-pdu-asynchronous-socket-close-oops.patch queue-3.18/target-avoid-mappedlun-symlink-creation-during-lun-shutdown.patch