Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Vitalii Dodonov <dreamer.two@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: stable@vger.kernel.org,target-devel@vger.kernel.org
Subject: [PATCH 0/1] scsi: target: iscsi: fix use-after-free in iscsit_stop_session()
Date: Sat, 21 Nov 2026 19:38:57 +0300	[thread overview]
Message-ID: <179527913740.32224.2426414360492240680@gmail.com> (raw)

The iSCSI target panics with a general protection fault inside
iscsit_stop_session() when a session that has more than one connection is
torn down while another thread closes one of those connections.

iscsit_stop_session() walks sess->sess_conn_list with
list_for_each_entry_safe() and drops sess->conn_lock inside the loop.  A
connection that is being shut down concurrently runs iscsit_close_connection(),
which removes itself from the list with list_del() under the same lock and
leaves LIST_POISON1 in conn->conn_list.next.  Pinning the next connection with
iscsit_inc_conn_usage_count() keeps the object alive, but not the list links,
so the following iteration computes conn_tmp = list_next_entry() from the
poisoned pointer and passes it to iscsit_inc_conn_usage_count(), which takes a
spinlock at *(conn_tmp + offsetof(conn_usage_lock)) and faults on
0xdead000000000004.

Crash, 7.3.0-11-generic, LIO target with MaxConnections=8, Microsoft iSCSI
initiator holding 8 MC/S connections, graceful reboot of the initiator while
I/O is in flight:

  Oops: general protection fault, probably for non-canonical address 0xdead000000000004: 0000 [#1] SMP PTI
  CPU: 0 UID: 0 PID: 9028 Comm: kworker/0:2 Not tainted 7.3.0-11-generic #12-Ubuntu PREEMPT(lazy)
  Workqueue: events iscsi_target_do_login_rx [iscsi_target_mod]
  RIP: 0010:_raw_spin_lock_bh+0x18/0x50
  RDI: dead000000000004   RBX: deacfffffffffcb0   R15: deacfffffffffcb0
  Call Trace:
   ? iscsit_inc_conn_usage_count+0x1b/0x40 [iscsi_target_mod]
   iscsit_stop_session+0x7d/0x1b0 [iscsi_target_mod]
   iscsi_check_for_session_reinstatement+0x1e1/0x290 [iscsi_target_mod]
   iscsi_target_handle_csg_one+0x135/0x160 [iscsi_target_mod]
   iscsi_target_do_login+0x32/0xe0 [iscsi_target_mod]
   iscsi_target_do_login_rx+0x2d2/0x420 [iscsi_target_mod]
   process_one_work+0x1dc/0x3f0
   ...
  Kernel panic - not syncing: Fatal exception in interrupt

The same fault is reachable from the logout path:
iscsit_stop_session <- iscsit_logout_post_handler <- iscsit_response_queue <-
iscsi_target_tx_thread, with the identical 0xdead000000000004.

Where it was first seen (field report).  A Proxmox VE host (7.0.14-9-pve,
later 7.0.14-28-pve) exported zvols through LIO to Windows 11 clients using
the Microsoft iSCSI initiator with MC/S.  The host had been stable for 95 days
with MaxConnections=1; after raising it to 2 there were four panics in one
night, all with the same general protection fault at 0xdead000000000004 and
the logout stack above, and the journal of one of them contains "Received
logout request on connection that is not in logged in state".  The panic also
reproduced on 7.0.14-28-pve, so it is not tied to a single build.  The module
carrying this fix has been running on that host for 9 days with
MaxConnections=4 and 72 active iSCSI connections, without a single panic.

Reproducer (any MC/S-capable initiator; open-iscsi does not implement MC/S, so
a Microsoft iSCSI initiator was used):

 1. LIO target with MaxConnections=8, no CHAP, generate_node_acls=1.  The
    value lives in configfs and is not exported by targetcli:

      echo 8 > /sys/kernel/config/target/iscsi/<iqn>/tpgt_1/param/MaxConnections

    With MaxConnections=1 the extra connection is refused with
    ISDSC_TOO_MANY_CONNECTIONS and nothing happens, so the target has to be
    configured first.

 2. Initiator: log in, for example on Windows

      Connect-IscsiTarget -NodeAddress <iqn> -TargetPortalAddress <ip>

    and then add the remaining connections to the *same* session, one call
    per connection:

      iscsicli SessionList                 # take the "Session Id"
      iscsicli ListInitiators              # -> ROOT\ISCSIPRT\0000_0
      iscsicli QAddConnection <SessionId> ROOT\ISCSIPRT\0000_0 <portal-ip>

    Repeat until the session holds MaxConnections connections.
    AddIScsiConnectionW() does the same thing programmatically, and the
    "MCS..." button in the iSCSI Initiator GUI (target -> Properties ->
    Sessions) as well.

 3. Bring the LUN online, mount a filesystem on it and start writing to it.

 4. Reboot the initiator gracefully while the I/O is still in flight; repeat.
    The stock module crashed on the 2nd-4th cycle (2 panics in ~20 minutes).

Results: stock module 2 crashes in 8 cycles, patched module 0 in 118 cycles
(the target stayed up for the whole run).

Patch 1/1 takes a snapshot of the connections, with a reference on each, while
conn_lock is held, and then works only on that snapshot; the order in which the
connections are reinstated is unchanged.

Vitalii Dodonov (1):
  scsi: target: iscsi: fix use-after-free in iscsit_stop_session()

 drivers/target/iscsi/iscsi_target.c | 68 ++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 21 deletions(-)

             reply	other threads:[~2026-11-21 16:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 16:38 Vitalii Dodonov [this message]
2026-11-21 16:38 ` [PATCH 1/1] scsi: target: iscsi: fix use-after-free in iscsit_stop_session() Vitalii Dodonov
2026-11-21 16:50   ` sashiko-bot

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=179527913740.32224.2426414360492240680@gmail.com \
    --to=dreamer.two@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox