Skip to content

scsi: target: iscsi: fix session use-after-free on non-leading login

Daniel Wade linux-scsi lkml target-devel 2 versions New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 0 repliesNew
  2. v13 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- 2/3: re-test every condition iscsi_login_non_zero_tsih_s2() tests, not just ->session_close. The Time2Retain timeout and the multi connection ERL=0 path both reach iscsit_close_session() without setting it.
- 2/3: publish conn_state inside the attach critical sections. Checking after it was already LOGGED_IN let iscsi_target_tx_thread() enter iscsit_close_connection() and wait on a conn_usage_count that the refusal path then deadlocked against with kthread_stop().
- Both were reported by Sashiko AI review on v1.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3scsi: target: iscsi: factor out iscsit_stop_kthreads()drivers/target/iscsi/iscsi_target_login.c drivers/target/iscsi/iscsi_target_login.h drivers/target/iscsi/iscsi_target_nego.c+20 -150 replies
2/3scsi: target: iscsi: don't attach a connection to a closing sessiondrivers/target/iscsi/iscsi_target.c drivers/target/iscsi/iscsi_target_login.c+59 -30 replies
3/3scsi: target: iscsi: don't re-arm Time2Retain on a closing sessiondrivers/target/iscsi/iscsi_target_login.c+7 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] scsi: target: iscsi: fix session use-after-free on non-leading login

A non-leading login can attach a connection to a session that iscsit_close_connection() has already committed to freeing. The connection ends up in full feature phase with conn->sess dangling and its NOP-In timer walking freed memory. The same window leaves an armed Time2Retain timer on a freed session when the login fails instead.

The bug dates to the driver's original merge in v3.1, but the fix keys off ->session_close, which arrived in v5.7 with commit 57c46e9f33da ("scsi: target: fix hang when multiple threads try to destroy the same iscsi session"), so a backport further back needs adjusting.

Tested with KASAN and lockdep on mainline against a target with authentication=0 and one explicit ACL. Compile tested on x86_64.

A reproducer is available on request.

v2:
- 2/3: re-test every condition iscsi_login_non_zero_tsih_s2() tests, not just ->session_close. The Time2Retain timeout and the multi connection ERL=0 path both reach iscsit_close_session() without setting it.
- 2/3: publish conn_state inside the attach critical sections. Checking after it was already LOGGED_IN let iscsi_target_tx_thread() enter iscsit_close_connection() and wait on a conn_usage_count that the refusal path then deadlocked against with kthread_stop().
- Both were reported by Sashiko AI review on v1.

v1: https://lore.kernel.org/linux-scsi/[email protected]/

Daniel Wade (3):
scsi: target: iscsi: factor out iscsit_stop_kthreads()
scsi: target: iscsi: don't attach a connection to a closing session
scsi: target: iscsi: don't re-arm Time2Retain on a closing session

 drivers/target/iscsi/iscsi_target.c       |  6 ++
 drivers/target/iscsi/iscsi_target_login.c | 81 +++++++++++++++++++++--
 drivers/target/iscsi/iscsi_target_login.h |  1 +
 drivers/target/iscsi/iscsi_target_nego.c  | 17 +----
 4 files changed, 86 insertions(+), 19 deletions(-)
Signature · 1 line
2.39.0.windows.2