scsi: libiscsi: move init ehwait to iscsi_session_setup()
PATCH 1/3 scsi: libiscsi: move init ehwait to iscsi_session_setup()
commit ec29d0ac29be ("scsi: iscsi: Fix conn use after free during resets") move member ehwait from conn to session, but left init ehwait in iscsi_conn_setup().
Due to one session can be binded by multi conns, the conn after the first will reinit the session->ehwait, move init ehwait to iscsi_session_setup() to fix it.
--- drivers/scsi/libiscsi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/libiscsi.c +1 -2
@@ -2947,6 +2947,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost, session->tmf_state =TMF_INITIAL ;timer_setup (&session->tmf_timer, iscsi_tmf_timedout,0 );mutex_init (&session->eh_mutex); +init_waitqueue_head (&session->ehwait);spin_lock_init (&session->frwd_lock);spin_lock_init (&session->back_lock);
@@ -3074,8 +3075,6 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size, goto login_task_data_alloc_fail; conn->login_task->data = conn->data = data; -init_waitqueue_head (&session->ehwait); -return cls_conn; login_task_data_alloc_fail:
Signature · 1 line
2.17.1
PATCH 2/3 scsi: libiscsi: fix invalid pointer dereference in iscsi_eh_session_reset
like commit 5db6dd14b313 ("scsi: libiscsi: Fix NULL pointer dereference in iscsi_eh_session_reset"), access conn->persistent_address here is not safe too.
The persistent_address is independent of conn refcount, so maybe already freed by iscsi_conn_teardown(), also we put the refcount of conn above, the conn pointer may be invalid.
--- drivers/scsi/libiscsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/libiscsi.c +2 -2
@@ -2531,8 +2531,8 @@ int iscsi_eh_session_reset(struct scsi_cmnd *sc)spin_lock_bh (&session->frwd_lock);if (session->state ==ISCSI_STATE_LOGGED_IN ) {ISCSI_DBG_EH (session, -"session reset succeeded for %s,%s\n" , - session->targetname, conn->persistent_address); +"session reset succeeded for %s\n" , + session->targetname); }else goto failed;spin_unlock_bh (&session->frwd_lock);
Signature · 1 line
2.17.1
PATCH 3/3 scsi: libiscsi: get ref to conn in iscsi_eh_device/target_reset()
In reply to Ding Huilike commit fda290c5ae98 ("scsi: iscsi: Get ref to conn during reset handling"), because in iscsi_exec_task_mgmt_fn(), the eh_mutex and frwd_lock will be unlock, the conn also can be released if we not hold ref.
--- drivers/scsi/libiscsi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/libiscsi.c +8 -2
@@ -2398,7 +2398,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) {struct iscsi_cls_session *cls_session;struct iscsi_session *session; -struct iscsi_conn *conn; +struct iscsi_conn *conn =NULL ;struct iscsi_tm *hdr;int rc =FAILED ;
@@ -2417,6 +2417,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)if (!session->leadconn || session->state !=ISCSI_STATE_LOGGED_IN ) goto unlock; conn = session->leadconn; +iscsi_get_conn (conn->cls_conn);/* only have one tmf outstanding at a time */ if (session->tmf_state !=TMF_INITIAL )
@@ -2463,6 +2464,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) done:ISCSI_DBG_EH (session,"dev reset result = %s\n" , rc ==SUCCESS ?"SUCCESS" :"FAILED" ); +if (conn) +iscsi_put_conn (conn->cls_conn);mutex_unlock (&session->eh_mutex);return rc; }
@@ -2560,7 +2563,7 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc) {struct iscsi_cls_session *cls_session;struct iscsi_session *session; -struct iscsi_conn *conn; +struct iscsi_conn *conn =NULL ;struct iscsi_tm *hdr;int rc =FAILED ;
@@ -2579,6 +2582,7 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc)if (!session->leadconn || session->state !=ISCSI_STATE_LOGGED_IN ) goto unlock; conn = session->leadconn; +iscsi_get_conn (conn->cls_conn);/* only have one tmf outstanding at a time */ if (session->tmf_state !=TMF_INITIAL )
@@ -2625,6 +2629,8 @@ static int iscsi_eh_target_reset(struct scsi_cmnd *sc) done:ISCSI_DBG_EH (session,"tgt %s reset result = %s\n" , session->targetname, rc ==SUCCESS ?"SUCCESS" :"FAILED" ); +if (conn) +iscsi_put_conn (conn->cls_conn);mutex_unlock (&session->eh_mutex);return rc; }
Signature · 1 line
2.17.1