Commit 42753cc4 authored by Hou Pu's avatar Hou Pu Committed by Greg Kroah-Hartman

scsi: target: iscsi: Fix hang in iscsit_access_np() when getting tpg->np_login_sem

commit ed43ffea 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: default avatarMike Christie <michael.christie@oracle.com>
Signed-off-by: default avatarHou Pu <houpu@bytedance.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent acfe0c7b
...@@ -1150,7 +1150,7 @@ iscsit_conn_set_transport(struct iscsi_conn *conn, struct iscsit_transport *t) ...@@ -1150,7 +1150,7 @@ iscsit_conn_set_transport(struct iscsi_conn *conn, struct iscsit_transport *t)
} }
void iscsi_target_login_sess_out(struct iscsi_conn *conn, void iscsi_target_login_sess_out(struct iscsi_conn *conn,
struct iscsi_np *np, bool zero_tsih, bool new_sess) bool zero_tsih, bool new_sess)
{ {
if (!new_sess) if (!new_sess)
goto old_sess_out; goto old_sess_out;
...@@ -1172,7 +1172,6 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn, ...@@ -1172,7 +1172,6 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
conn->sess = NULL; conn->sess = NULL;
old_sess_out: old_sess_out:
iscsi_stop_login_thread_timer(np);
/* /*
* If login negotiation fails check if the Time2Retain timer * If login negotiation fails check if the Time2Retain timer
* needs to be restarted. * needs to be restarted.
...@@ -1432,8 +1431,9 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) ...@@ -1432,8 +1431,9 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
new_sess_out: new_sess_out:
new_sess = true; new_sess = true;
old_sess_out: old_sess_out:
iscsi_stop_login_thread_timer(np);
tpg_np = conn->tpg_np; tpg_np = conn->tpg_np;
iscsi_target_login_sess_out(conn, np, zero_tsih, new_sess); iscsi_target_login_sess_out(conn, zero_tsih, new_sess);
new_sess = false; new_sess = false;
if (tpg) { if (tpg) {
......
...@@ -14,8 +14,7 @@ extern int iscsit_put_login_tx(struct iscsi_conn *, struct iscsi_login *, u32); ...@@ -14,8 +14,7 @@ extern int iscsit_put_login_tx(struct iscsi_conn *, struct iscsi_login *, u32);
extern void iscsit_free_conn(struct iscsi_np *, struct iscsi_conn *); extern void iscsit_free_conn(struct iscsi_np *, struct iscsi_conn *);
extern int iscsit_start_kthreads(struct iscsi_conn *); extern int iscsit_start_kthreads(struct iscsi_conn *);
extern void iscsi_post_login_handler(struct iscsi_np *, struct iscsi_conn *, u8); extern void iscsi_post_login_handler(struct iscsi_np *, struct iscsi_conn *, u8);
extern void iscsi_target_login_sess_out(struct iscsi_conn *, struct iscsi_np *, extern void iscsi_target_login_sess_out(struct iscsi_conn *, bool, bool);
bool, bool);
extern int iscsi_target_login_thread(void *); extern int iscsi_target_login_thread(void *);
#endif /*** ISCSI_TARGET_LOGIN_H ***/ #endif /*** ISCSI_TARGET_LOGIN_H ***/
...@@ -548,12 +548,11 @@ static bool iscsi_target_sk_check_and_clear(struct iscsi_conn *conn, unsigned in ...@@ -548,12 +548,11 @@ static bool iscsi_target_sk_check_and_clear(struct iscsi_conn *conn, unsigned in
static void iscsi_target_login_drop(struct iscsi_conn *conn, struct iscsi_login *login) static void iscsi_target_login_drop(struct iscsi_conn *conn, struct iscsi_login *login)
{ {
struct iscsi_np *np = login->np;
bool zero_tsih = login->zero_tsih; bool zero_tsih = login->zero_tsih;
iscsi_remove_failed_auth_entry(conn); iscsi_remove_failed_auth_entry(conn);
iscsi_target_nego_release(conn); iscsi_target_nego_release(conn);
iscsi_target_login_sess_out(conn, np, zero_tsih, true); iscsi_target_login_sess_out(conn, zero_tsih, true);
} }
static void iscsi_target_login_timeout(unsigned long data) static void iscsi_target_login_timeout(unsigned long data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment