android_kernel_samsung_msm8976/drivers/target
Nicholas Bellinger be923a2b86 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>
Cc: stable@vger.kernel.org # 3.10+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
2019-07-27 21:44:16 +02:00
..
iscsi iscsi-target: Fix potential dead-lock during node acl delete 2016-02-25 11:57:47 -08:00
loopback
sbp
tcm_fc
Kconfig
Makefile
target_core_alua.c
target_core_alua.h
target_core_configfs.c
target_core_device.c
target_core_fabric_configfs.c target: Avoid mappedlun symlink creation during lun shutdown 2019-07-27 21:44:16 +02:00
target_core_fabric_lib.c
target_core_file.c
target_core_file.h
target_core_hba.c
target_core_iblock.c
target_core_iblock.h
target_core_internal.h
target_core_pr.c
target_core_pr.h
target_core_pscsi.c target/pscsi: Fix TYPE_TAPE + TYPE_MEDIMUM_CHANGER export 2019-07-27 21:43:39 +02:00
target_core_pscsi.h
target_core_rd.c
target_core_rd.h
target_core_sbc.c
target_core_spc.c
target_core_stat.c
target_core_tmr.c
target_core_tpg.c target: Avoid mappedlun symlink creation during lun shutdown 2019-07-27 21:44:16 +02:00
target_core_transport.c
target_core_ua.c
target_core_ua.h