1
0
Fork 0
alistair23-linux/drivers/target/iscsi
Hou Pu a5bfcf2455 scsi: target: iscsi: Fix hang in iscsit_access_np() when getting tpg->np_login_sem
commit ed43ffea78 upstream.

The iSCSI target login thread might get stuck with the following stack:

cat /proc/`pidof iscsi_np`/stack
[<0>] down_interruptible+0x42/0x50
[<0>] iscsit_access_np+0xe3/0x167
[<0>] iscsi_target_locate_portal+0x695/0x8ac
[<0>] __iscsi_target_login_thread+0x855/0xb82
[<0>] iscsi_target_login_thread+0x2f/0x5a
[<0>] kthread+0xfa/0x130
[<0>] ret_from_fork+0x1f/0x30

This can be reproduced via the following steps:

1. Initiator A tries to log in to iqn1-tpg1 on port 3260. After finishing
   PDU exchange in the login thread and before the negotiation is finished
   the the network link goes down. At this point A has not finished login
   and tpg->np_login_sem is held.

2. Initiator B tries to log in to iqn2-tpg1 on port 3260. After finishing
   PDU exchange in the login thread the target expects to process remaining
   login PDUs in workqueue context.

3. Initiator A' tries to log in to iqn1-tpg1 on port 3260 from a new
   socket. A' will wait for tpg->np_login_sem with np->np_login_timer
   loaded to wait for at most 15 seconds. The lock is held by A so A'
   eventually times out.

4. Before A' got timeout initiator B gets negotiation failed and calls
   iscsi_target_login_drop()->iscsi_target_login_sess_out().  The
   np->np_login_timer is canceled and initiator A' will hang forever.
   Because A' is now in the login thread, no new login requests can be
   serviced.

Fix this by moving iscsi_stop_login_thread_timer() out of
iscsi_target_login_sess_out(). Also remove iscsi_np parameter from
iscsi_target_login_sess_out().

Link: https://lore.kernel.org/r/20200729130343.24976-1-houpu@bytedance.com
Cc: stable@vger.kernel.org
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Hou Pu <houpu@bytedance.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-09-17 13:47:53 +02:00
..
cxgbit
Kconfig
Makefile
iscsi_target.c scsi: target: iscsi: Fix data digest calculation 2020-09-17 13:47:52 +02:00
iscsi_target.h scsi: target: remove boilerplate code 2020-04-21 09:05:04 +02:00
iscsi_target_auth.c
iscsi_target_auth.h
iscsi_target_configfs.c scsi: target: fix hang when multiple threads try to destroy the same iscsi session 2020-04-21 09:05:04 +02:00
iscsi_target_datain_values.c
iscsi_target_datain_values.h
iscsi_target_device.c
iscsi_target_device.h
iscsi_target_erl0.c
iscsi_target_erl0.h
iscsi_target_erl1.c
iscsi_target_erl1.h
iscsi_target_erl2.c
iscsi_target_erl2.h
iscsi_target_login.c scsi: target: iscsi: Fix hang in iscsit_access_np() when getting tpg->np_login_sem 2020-09-17 13:47:53 +02:00
iscsi_target_login.h scsi: target: iscsi: Fix hang in iscsit_access_np() when getting tpg->np_login_sem 2020-09-17 13:47:53 +02:00
iscsi_target_nego.c scsi: target: iscsi: Fix hang in iscsit_access_np() when getting tpg->np_login_sem 2020-09-17 13:47:53 +02:00
iscsi_target_nego.h
iscsi_target_nodeattrib.c
iscsi_target_nodeattrib.h
iscsi_target_parameters.c
iscsi_target_parameters.h
iscsi_target_seq_pdu_list.c
iscsi_target_seq_pdu_list.h
iscsi_target_stat.c
iscsi_target_tmr.c
iscsi_target_tmr.h
iscsi_target_tpg.c
iscsi_target_tpg.h
iscsi_target_transport.c
iscsi_target_util.c
iscsi_target_util.h