From: sashiko-bot@kernel.org
To: "Rongen Wang" <security@nitrohex.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH] scsi: target: iscsi: Refuse to add a connection to a session being closed
Date: Fri, 27 Nov 2026 12:21:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-237357@kernel.org> (raw)
In-Reply-To: <20261127-b4-lio-iscsi-session-closing-v1-1-cdf2bbbef87a@nitrohex.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] scsi: target: iscsi: missing Time2Retain check in
iscsi_post_login_handler()
- [Medium] scsi: target: iscsi: premature param cleanup in
iscsi_post_login_handler()
--
commit 9055d1b28301fad93aa7addf4bcf0bf18f5835d0
Author: Rongen Wang <security@nitrohex.com>
scsi: target: iscsi: Refuse to add a connection to a session being closed
This commit checks under sess->conn_lock in iscsi_post_login_handler()
whether a session is shutting down before attaching a new non-zero TSIH
connection, and stops the connection's kthreads if the login is refused.
> diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
> index fda04eb15d3a2..717628000472f 100644
> --- a/drivers/target/iscsi/iscsi_target_login.c
> +++ b/drivers/target/iscsi/iscsi_target_login.c
[ ... ]
> @@ -674,6 +699,32 @@ void iscsi_post_login_handler(
> conn->param_list = NULL;
>
> spin_lock_bh(&sess->conn_lock);
> + /*
> + * The session was located from ISID+TSIH when the first Login
> + * Request arrived, and since then only the session usage count
> + * kept it alive. If its last connection went away in the
> + * meantime, iscsit_close_connection() has already committed to
> + * iscsit_close_session(), which frees the session as soon as
> + * the usage count is dropped. Do not attach a new connection
> + * to a session that is being shut down. iscsit_close_connection()
> + * makes that decision under sess->conn_lock as well.
> + */
> + if (atomic_read(&sess->session_fall_back_to_erl0) ||
> + atomic_read(&sess->session_logout) ||
> + atomic_read(&sess->session_close)) {
[Severity: High]
Can a pending non-zero TSIH login still attach to a session that is closing
due to Time2Retain expiry?
When a non-zero TSIH login starts while another connection is still logged in
on the session, iscsi_login_non_zero_tsih_s2() sees sess->session_state !=
TARG_SESS_STATE_FAILED and leaves sess->session_continuation at 0 while
holding a session usage count. If the active connection then closes via a
CLOSE_CONNECTION logout (or fails at ErrorRecoveryLevel=2),
iscsit_close_connection() does not set session_fall_back_to_erl0,
session_logout, or session_close; instead it moves the session to
TARG_SESS_STATE_FAILED and starts the Time2Retain timer.
When that timer expires, iscsit_time2retain_work() sets ISCSI_TF_EXPIRED under
se_tpg->session_lock (without taking sess->conn_lock) and calls
iscsit_close_session(sess, false):
CPU0 (login worker) CPU1 (iscsit_time2retain_work)
iscsi_login_non_zero_tsih_s2()
iscsit_inc_session_usage_count()
/* session_continuation == 0 */
...
/* last active conn closes, Time2Retain starts and expires */
spin_lock_bh(&se_tpg->session_lock)
sess->time2retain_timer_flags |=
ISCSI_TF_EXPIRED
spin_unlock_bh(&se_tpg->session_lock)
iscsit_close_session(sess, false)
iscsi_post_login_handler()
spin_lock_bh(&sess->conn_lock)
/* fall_back_to_erl0, logout,
* and close are all 0 */
list_add_tail(&conn->conn_list,
&sess->sess_conn_list)
atomic_inc(&sess->nconn)
spin_unlock_bh(&sess->conn_lock)
if (atomic_read(&sess->nconn))
BUG();
Depending on the interleaving with iscsit_close_session(sess, false),
iscsit_close_session() either hits BUG() on atomic_read(&sess->nconn), frees
sess after iscsi_post_login_handler() drops session_usage_count (causing the
same use-after-free in iscsit_get_rx_pdu()), or finishes First-stage teardown
(transport_deregister_session_configfs() and setting session_reinstatement =
1), sees session_usage_count > 0 in iscsit_check_session_usage_count(sess,
false), and resets session_logout back to 0, allowing the new connection to
attach to a half-closed session that can never be freed.
> + spin_unlock_bh(&sess->conn_lock);
> + pr_err("iSCSI session SID %u is shutting down, refusing to add CID %u\n",
> + sess->sid, conn->cid);
> + iscsit_dec_conn_usage_count(conn);
> + return -1;
> + }
[Severity: Medium]
Does returning -1 here after iscsi_set_session_parameters() and
iscsi_release_param_list() corrupt sess->sess_ops and the failure statistics
in iscsi_target_login_sess_out()?
At the start of the !zero_tsih branch, before taking sess->conn_lock,
iscsi_post_login_handler() modifies sess->sess_ops and frees and clears
conn->param_list. When this check refuses the login, the caller invokes
iscsi_target_login_sess_out(conn, zero_tsih, true) ->
iscsit_collect_login_stats(), which finds conn->param_list == NULL and
overwrites ls->last_intr_fail_name with "Unknown". Moving
iscsi_set_session_parameters() and iscsi_release_param_list() after the
shutdown check avoids mutating sess->sess_ops on a dying session and lets
iscsi_target_login_sess_out() record the initiator name and free
conn->param_list.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-b4-lio-iscsi-session-closing-v1-1-cdf2bbbef87a@nitrohex.com?part=1
prev parent reply other threads:[~2026-11-27 12:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 12:00 [PATCH] scsi: target: iscsi: Refuse to add a connection to a session being closed Rongen Wang
2026-11-27 12:00 ` Rongen Wang via B4 Relay
2026-11-27 12:21 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-237357@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=security@nitrohex.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.