scsi: iscsi: Fix race condition between login and sync thread
authorGulam Mohamed <gulam.mohamed@oracle.com>
Thu, 25 Mar 2021 09:32:48 +0000 (09:32 +0000)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 30 Mar 2021 01:17:45 +0000 (21:17 -0400)
commit9e67600ed6b8565da4b85698ec659b5879a6c1c6
tree8814c418675a2da4851ce46c268f7204783dbf39
parent36fa766faa0c822c860e636fe82b1affcd022974
scsi: iscsi: Fix race condition between login and sync thread

A kernel panic was observed due to a timing issue between the sync thread
and the initiator processing a login response from the target. The session
reopen can be invoked both from the session sync thread when iscsid
restarts and from iscsid through the error handler. Before the initiator
receives the response to a login, another reopen request can be sent from
the error handler/sync session. When the initial login response is
subsequently processed, the connection has been closed and the socket has
been released.

To fix this a new connection state, ISCSI_CONN_BOUND, is added:

 - Set the connection state value to ISCSI_CONN_DOWN upon
   iscsi_if_ep_disconnect() and iscsi_if_stop_conn()

 - Set the connection state to the newly created value ISCSI_CONN_BOUND
   after bind connection (transport->bind_conn())

 - In iscsi_set_param(), return -ENOTCONN if the connection state is not
   either ISCSI_CONN_BOUND or ISCSI_CONN_UP

Link: https://lore.kernel.org/r/20210325093248.284678-1-gulam.mohamed@oracle.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Gulam Mohamed <gulam.mohamed@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
index 91074fd97f64..f4bf62b007a0 100644
drivers/scsi/scsi_transport_iscsi.c
include/scsi/scsi_transport_iscsi.h