[PATCH 3/3] scsi: target: iscsi: don't re-arm Time2Retain on a closing session
From: Daniel Wade
Date: Sun Nov 15 2026 - 03:59:56 EST
iscsi_target_login_sess_out() re-arms the Time2Retain timer of the
session whose login just failed. In the window closed by the previous
patch that session may already be on its way out: iscsit_close_session()
stops that timer, then sleeps in iscsit_check_session_usage_count() on
the reference this path is about to drop, and frees the session as soon
as it is dropped. A re-arm therefore lands between the stop and the
free, and leaves an armed timer on freed memory.
->session_close is set before the free is committed to, so test it here
too and skip the re-arm.
Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Daniel Wade <danjwade95@xxxxxxxxx>
---
drivers/target/iscsi/iscsi_target_login.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
index de0cd95aff0..1f41e5274f2 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -1168,7 +1168,13 @@ void iscsi_target_login_sess_out(struct iscsit_conn *conn,
*/
if (!zero_tsih && conn->sess) {
spin_lock_bh(&conn->sess->conn_lock);
- if (conn->sess->session_state == TARG_SESS_STATE_FAILED) {
+ /*
+ * iscsit_close_session() stopped this timer before sleeping on
+ * the usage count this path drops, so re-arming it would leave
+ * the timer armed on freed memory.
+ */
+ if (conn->sess->session_state == TARG_SESS_STATE_FAILED &&
+ !atomic_read(&conn->sess->session_close)) {
struct se_portal_group *se_tpg =
&conn->tpg->tpg_se_tpg;
--
2.39.0.windows.2