[PATCH 3/3] scsi: libiscsi: get ref to conn in iscsi_eh_device/target_reset()

7 views
Skip to first unread message

Ding Hui

unread,
Sep 9, 2021, 3:24:19 PM9/9/21
to ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, michael....@oracle.co, open-...@googlegroups.com, linux-...@vger.kernel.org, Ding Hui
like 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.

Signed-off-by: Ding Hui <din...@sangfor.com.cn>
---
drivers/scsi/libiscsi.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 69b3b2148328..4d3b37c20f8a 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -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;
}
--
2.17.1

Ding Hui

unread,
Sep 9, 2021, 3:24:19 PM9/9/21
to ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, michael....@oracle.co, open-...@googlegroups.com, linux-...@vger.kernel.org, Ding Hui
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.

Fixes: ec29d0ac29be ("scsi: iscsi: Fix conn use after free during resets")
Signed-off-by: Ding Hui <din...@sangfor.com.cn>
---
drivers/scsi/libiscsi.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 4683c183e9d4..712a45368385 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -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:
--
2.17.1

Ding Hui

unread,
Sep 9, 2021, 9:03:04 PM9/9/21
to ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, martin....@oracle.com, michael....@oracle.com, open-...@googlegroups.com, linux...@vger.kernel.org, linux-...@vger.kernel.org, Ding Hui

Mike Christie

unread,
Sep 10, 2021, 12:25:36 PM9/10/21
to Ding Hui, ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, martin....@oracle.com, open-...@googlegroups.com, linux...@vger.kernel.org, linux-...@vger.kernel.org
On 9/9/21 8:02 PM, Ding Hui wrote:
> 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

A session can only have 1 conn. There is some code that makes it look
like we can do multiple conns or swap the single conn, but it was never
fully implemented/supported upstream.

However, I like the patch. The init should be done in iscsi_session_setup,
so could you fix up the commit, so it's correct?

Ding Hui

unread,
Sep 11, 2021, 5:38:21 AM9/11/21
to Mike Christie, ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, martin....@oracle.com, open-...@googlegroups.com, linux...@vger.kernel.org, linux-...@vger.kernel.org
On 2021/9/11 12:25 上午, Mike Christie wrote:
> On 9/9/21 8:02 PM, Ding Hui wrote:
>> 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
>
> A session can only have 1 conn. There is some code that makes it look
> like we can do multiple conns or swap the single conn, but it was never
> fully implemented/supported upstream.
>
> However, I like the patch. The init should be done in iscsi_session_setup,
> so could you fix up the commit, so it's correct?
>

Thanks,I'll update the commit log and send v2 1/3.
--
Thanks,
-dinghui

Ding Hui

unread,
Sep 11, 2021, 9:55:24 AM9/11/21
to ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, martin....@oracle.com, michael....@oracle.com, open-...@googlegroups.com, linux...@vger.kernel.org, linux-...@vger.kernel.org, Ding Hui
The 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().

Although a session can only have 1 conn currently, it is better to
do init ehwait in iscsi_session_setup() to prevent reinit by mistake,
also in case we can handle multiple conns in the future.

Fixes: ec29d0ac29be ("scsi: iscsi: Fix conn use after free during resets")
Signed-off-by: Ding Hui <din...@sangfor.com.cn>
---
v2:
update commit log

drivers/scsi/libiscsi.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 4683c183e9d4..712a45368385 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -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:
--
2.17.1

Mike Christie

unread,
Sep 13, 2021, 11:23:37 AM9/13/21
to Ding Hui, ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, martin....@oracle.com, open-...@googlegroups.com, linux...@vger.kernel.org, linux-...@vger.kernel.org
Reviewed-by: Mike Christie <michael....@oracle.com>

Martin K. Petersen

unread,
Sep 14, 2021, 12:05:27 AM9/14/21
to Ding Hui, ldu...@suse.com, cle...@redhat.com, je...@linux.ibm.com, martin....@oracle.com, michael....@oracle.com, open-...@googlegroups.com, linux...@vger.kernel.org, linux-...@vger.kernel.org

Ding,

> The 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().
>
> Although a session can only have 1 conn currently, it is better to do
> init ehwait in iscsi_session_setup() to prevent reinit by mistake,
> also in case we can handle multiple conns in the future.

Applied to 5.16/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering

Martin K. Petersen

unread,
Sep 22, 2021, 12:45:43 AM9/22/21
to michael....@oracle.com, ldu...@suse.com, linux...@vger.kernel.org, linux-...@vger.kernel.org, Ding Hui, je...@linux.ibm.com, open-...@googlegroups.com, cle...@redhat.com, Martin K . Petersen
On Sat, 11 Sep 2021 21:51:59 +0800, Ding Hui wrote:

> The 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().
>
> Although a session can only have 1 conn currently, it is better to
> do init ehwait in iscsi_session_setup() to prevent reinit by mistake,
> also in case we can handle multiple conns in the future.
>
> [...]

Applied to 5.16/scsi-queue, thanks!

[1/1] scsi: libiscsi: move init ehwait to iscsi_session_setup()
https://git.kernel.org/mkp/scsi/c/e018f03d6ccb
Reply all
Reply to author
Forward
0 new messages