Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Jiayuan Liang <ljykernel@gmail.com>
To: lduncan@suse.com, cleech@redhat.com, michael.christie@oracle.com,
	James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com
Cc: open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, Jiayuan Liang <ljykernel@gmail.com>
Subject: [PATCH] scsi: iscsi_tcp: Fix null-pointer dereference in iscsi_sw_tcp_conn_restore_callbacks
Date: Wed,  5 Aug 2026 14:53:26 +0800	[thread overview]
Message-ID: <20260805065326.1952-1-ljykernel@gmail.com> (raw)

A null-pointer dereference can occur in
iscsi_sw_tcp_conn_restore_callbacks() due to a race condition
leading to concurrent/re-entrant invocations of
iscsi_sw_tcp_release_conn().

Specifically, the re-entrancy can be triggered under the
following scenario:

1. The iSCSI client initiates a logout, actively stopping the
   connection via:
   iscsi_if_stop_conn()
     -> iscsi_stop_conn(..., STOP_CONN_TERM)
          -> cancel_work_sync(&conn->cleanup_work)
          -> iscsi_sw_tcp_release_conn()

2. Simultaneously, a server disconnect triggers a heartbeat
   timeout on the client side, executing the timeout path:
   iscsi_check_transport_timeouts()
     -> iscsi_conn_failure()
          -> iscsi_conn_error_event()
               -> queue_work(..., &conn->cleanup_work)

   This schedules iscsi_cleanup_conn_work_fn(), which calls:
   iscsi_cleanup_conn_work_fn()
     -> iscsi_stop_conn(..., STOP_CONN_RECOVER)
          -> iscsi_sw_tcp_release_conn()

If these two paths execute concurrently, iscsi_sw_tcp_release_conn()
is re-entered. Since the first invocation releases the socket and
sets tcp_sw_conn->sock to NULL, the subsequent re-entrant
invocation in iscsi_sw_tcp_conn_restore_callbacks() attempts to
dereference the NULL pointer at `tcp_sw_conn->sock->sk`, resulting
in a kernel panic (Oops):

BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
Oops: 0000 [#1] SMP PTI
Workqueue: iscsi_conn_cleanup iscsi_cleanup_conn_work_fn [scsi_transport_iscsi]
RIP: 0010:iscsi_sw_tcp_release_conn+0x54/0x110 [iscsi_tcp]
Call Trace:
 iscsi_sw_tcp_conn_stop+0x5d/0x80 [iscsi_tcp]
 iscsi_stop_conn+0x66/0xc0 [scsi_transport_iscsi]
 iscsi_cleanup_conn_work_fn+0x6e/0xb0 [scsi_transport_iscsi]
 process_one_work+0x1a7/0x360
 worker_thread+0x30/0x390
 kthread+0x10a/0x120
 ret_from_fork+0x35/0x40

Fix this by adding a NULL check for `tcp_sw_conn->sock` in
iscsi_sw_tcp_conn_restore_callbacks() before attempting to access
the socket's internal fields.

Signed-off-by: Jiayuan Liang <ljykernel@gmail.com>
---
 drivers/scsi/iscsi_tcp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 9260b1c9b0e0..0eabb8b59f46 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -265,8 +265,12 @@ iscsi_sw_tcp_conn_restore_callbacks(struct iscsi_conn *conn)
 {
 	struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
 	struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
-	struct sock *sk = tcp_sw_conn->sock->sk;
+	struct sock *sk;
 
+	if (!tcp_sw_conn->sock)
+		return;
+
+	sk = tcp_sw_conn->sock->sk;
 	/* restore socket callbacks, see also: iscsi_sw_tcp_conn_set_callbacks() */
 	write_lock_bh(&sk->sk_callback_lock);
 	sk->sk_user_data    = NULL;
@@ -277,6 +281,7 @@ iscsi_sw_tcp_conn_restore_callbacks(struct iscsi_conn *conn)
 	write_unlock_bh(&sk->sk_callback_lock);
 }
 
+
 /**
  * iscsi_sw_tcp_xmit_segment - transmit segment
  * @tcp_conn: the iSCSI TCP connection
-- 
2.43.0


             reply	other threads:[~2026-08-05  6:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  6:53 Jiayuan Liang [this message]
2026-08-05  7:25 ` [PATCH] scsi: iscsi_tcp: Fix null-pointer dereference in iscsi_sw_tcp_conn_restore_callbacks sashiko-bot
2026-08-05 20:42 ` Mike Christie

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=20260805065326.1952-1-ljykernel@gmail.com \
    --to=ljykernel@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=cleech@redhat.com \
    --cc=lduncan@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=open-iscsi@googlegroups.com \
    /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