Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself
@ 2026-11-16 10:11 Yehyeong Lee
  2026-11-16 10:11 ` [PATCH 2/2] IB/isert: do not leak the receive descriptor of a dropped Data-Out Yehyeong Lee
  2026-11-16 10:30 ` [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Yehyeong Lee @ 2026-11-16 10:11 UTC (permalink / raw)
  To: sagi, jgg, leon; +Cc: linux-rdma, target-devel, linux-scsi, linux-kernel

iscsit_add_reject() builds the Reject from a command of its own, with
iscsit_allocate_cmd(), and iscsit_allocate_cmd() zeroes sizeof(struct
iscsit_cmd) plus the transport's priv_size.  For iSER that zeroes struct
isert_cmd too, so conn, iscsit_cmd and rx_desc are all NULL where
isert_allocate_cmd() would have filled them in.  The target's tx thread
then takes that command through isert_response_queue() ->
isert_put_reject() -> isert_post_response(), which hands the NULL
descriptor to isert_post_recv() and dereferences it.

One PDU after login is enough.  iscsit_check_dataout_hdr() answers a
Data-Out whose DataSegmentLength exceeds
conn_ops->MaxXmitDataSegmentLength with iscsit_add_reject(), and it does
so before it looks the ITT up, so there is no SCSI command involved.
Against a LIO target with an iSER portal over soft-RoCE, with
TargetRecvDataSegmentLength negotiated down to 512 and one Data-Out
declaring and carrying 1024 bytes, 5 boots out of 5:

  [    3.750347] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000484: 0000 [#1] SMP KASAN NOPTI
  [    3.752656] KASAN: probably user-memory-access in range [0x0000000000002420-0x0000000000002427]
  [    3.753703] CPU: 0 UID: 0 PID: 168 Comm: iscsi_ttx Not tainted 7.4.0-rc2-RJ6A-00716-g23c62304dde2 #1 PREEMPT(lazy)
  [    3.755172] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
  [    3.756829] RIP: 0010:isert_post_recv+0x98/0x210
  [    3.757519] Code: 89 f8 48 c7 44 24 48 00 00 00 00 48 c7 44 24 50 00 00 00 00 48 c1 e8 03 48 c7 44 24 58 00 00 00 00 48 c7 44 24 60 00 00 00 00 <0f> b6 04 10 84 c0 74 06 0f 8e 2c 01 00 00 31 ed 80 be 20 24 00 00
  [    3.759855] RSP: 0018:ffff888104ecfc10 EFLAGS: 00010206
  [    3.760580] RAX: 0000000000000484 RBX: 1ffff110209d9f83 RCX: 0000000000000001
  [    3.761476] RDX: dffffc0000000000 RSI: 0000000000000000 RDI: 0000000000002420
  [    3.762376] RBP: ffff888109625380 R08: 000000000000029d R09: 0000000000000001
  [    3.763288] R10: ffff888104d95447 R11: 00000000eb6dcbe3 R12: ffff888104af8000
  [    3.764184] R13: ffff888104af8000 R14: ffff888104b4f000 R15: ffff888109624f00
  [    3.765076] FS:  0000000000000000(0000) GS:ffff88816b45d000(0000) knlGS:0000000000000000
  [    3.766100] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  [    3.766830] CR2: 00007f5dc1281000 CR3: 0000000104baf004 CR4: 0000000000770ef0
  [    3.767739] PKRU: 55555554
  [    3.768091] Call Trace:
  [    3.768407]  <TASK>
  [    3.768679]  ? __pfx_isert_post_recv+0x10/0x10
  [    3.769233]  isert_post_response+0x85/0x1b0
  [    3.769745]  ? __pfx_isert_post_response+0x10/0x10
  [    3.770338]  ? isert_response_queue+0x91d/0x19a0
  [    3.770898]  iscsi_target_tx_thread+0x3de/0x6f0
  [    3.771460]  ? __pfx_iscsi_target_tx_thread+0x10/0x10
  [    3.772062]  ? _raw_spin_lock_irq+0x10/0xe0
  [    3.772546]  ? __pfx_autoremove_wake_function+0x10/0x10
  [    3.773148]  ? __pfx_kthread_affine_node+0x10/0x10
  [    3.773714]  ? __kthread_parkme+0x88/0x170
  [    3.774196]  ? __pfx_iscsi_target_tx_thread+0x10/0x10
  [    3.774775]  ? __pfx_iscsi_target_tx_thread+0x10/0x10
  [    3.775352]  kthread+0x2c8/0x3b0
  [    3.775733]  ? recalc_sigpending+0x15c/0x1e0
  [    3.776236]  ? __pfx_kthread+0x10/0x10
  [    3.776671]  ret_from_fork+0x36e/0x5a0
  [    3.777109]  ? __pfx_ret_from_fork+0x10/0x10
  [    3.777604]  ? __switch_to+0x572/0xdc0
  [    3.778041]  ? __pfx_kthread+0x10/0x10
  [    3.778482]  ret_from_fork_asm+0x1a/0x30
  [    3.778937]  </TASK>
  [    3.779201] Modules linked in:
  [    3.779592] ---[ end trace 0000000000000000 ]---

The tx thread dies there, and the teardown that follows walks into the
connection it was using: a KASAN slab-use-after-free in do_send_sig_info()
from iscsit_cause_connection_reinstatement(), a refcount warning in
iscsit_close_connection() and a second Oops in kthread_stop().

So let isert_post_recv() accept a command that has no descriptor, beside
the already-reposted case it tolerates today, and fill in the two
back-pointers the completion path needs, which isert_put_cmd() is
already written for - its ISCSI_OP_REJECT arm releases a command whose
se_cmd was never set up.

The unsolicited NOP-In is the same shape and is already kept away from
iSER: iscsit_add_nopin() allocates its command the same way, and
iscsi_post_login_start_timers() does not arm that timer for
ISCSI_INFINIBAND.

Fixes: 4366b19ca5eb ("iser-target: Change the recv buffers posting logic")
Cc: stable@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
 drivers/infiniband/ulp/isert/ib_isert.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index efa8d7b7844c97..81164881dcc241 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -758,7 +758,8 @@ isert_post_recv(struct isert_conn *isert_conn, struct iser_rx_desc *rx_desc)
 	struct ib_recv_wr rx_wr;
 	int ret;
 
-	if (!rx_desc->in_use) {
+	/* A command iscsit_add_reject() allocated has no descriptor. */
+	if (!rx_desc || !rx_desc->in_use) {
 		/*
 		 * if the descriptor is not in-use we already reposted it
 		 * for recv, so just silently return
@@ -1958,6 +1959,9 @@ isert_put_reject(struct iscsit_cmd *cmd, struct iscsit_conn *conn)
 	struct iscsi_reject *hdr =
 		(struct iscsi_reject *)&isert_cmd->tx_desc.iscsi_header;
 
+	isert_cmd->conn = isert_conn;
+	isert_cmd->iscsit_cmd = cmd;
+
 	isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
 	iscsit_build_reject(cmd, conn, hdr);
 	isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] IB/isert: do not leak the receive descriptor of a dropped Data-Out
  2026-11-16 10:11 [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself Yehyeong Lee
@ 2026-11-16 10:11 ` Yehyeong Lee
  2026-11-16 10:30 ` [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Yehyeong Lee @ 2026-11-16 10:11 UTC (permalink / raw)
  To: sagi, jgg, leon; +Cc: linux-rdma, target-devel, linux-scsi, linux-kernel

isert_handle_iscsi_dataout() works on the command it finds by ITT, which
holds the descriptor of the SCSI Command PDU and not of this Data-Out,
which is why the function posts its own descriptor explicitly when it
succeeds.  None of its other returns do, and isert_recv_done() ignores
what the handler returned, so each such Data-Out costs one of the
ISERT_QP_MAX_RECV_DTOS buffers.  That includes the returns where
iscsit_check_dataout_hdr() answers 0 without a command at all: 200
Data-Outs carrying an ITT that matches no command stop the connection
after exactly 128 of them, in all 3 runs, with no response to a NOP-Out
sent afterwards and nothing logged beyond the per-PDU "Unable to locate
ITT" message; with this patch all 200 are taken and the NOP-Out is
answered.

So give isert_handle_iscsi_dataout()'s other returns the same post its
success path already does.

That one function only.  Everywhere else a handler returns non-zero, the
command isert allocated still holds that descriptor and the response
posts it from isert_post_response(), so re-posting from
isert_recv_done() would post the same descriptor twice; the second post
is skipped only while the descriptor has not been refilled, which is not
something the receive path can promise.  iscsit_handle_logout_cmd() even
returns 1 for an ordinary logout.

Fixes: 4366b19ca5eb ("iser-target: Change the recv buffers posting logic")
Cc: stable@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
 drivers/infiniband/ulp/isert/ib_isert.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 81164881dcc241..8a57c880335cc3 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -1130,17 +1130,16 @@ isert_handle_iscsi_dataout(struct isert_conn *isert_conn,
 	int rc, sg_nents, sg_off, page_off;
 
 	rc = iscsit_check_dataout_hdr(conn, buf, &cmd);
-	if (rc < 0)
-		return rc;
-	else if (!cmd)
-		return 0;
+	if (rc < 0 || !cmd)
+		goto repost;
 	/*
 	 * FIXME: Unexpected unsolicited_data out
 	 */
 	if (!cmd->unsolicited_data) {
 		isert_err("Received unexpected solicited data payload\n");
 		dump_stack();
-		return -1;
+		rc = -1;
+		goto repost;
 	}
 
 	isert_dbg("Unsolicited DataOut unsol_data_len: %u, "
@@ -1158,7 +1157,8 @@ isert_handle_iscsi_dataout(struct isert_conn *isert_conn,
 	if (page_off) {
 		isert_err("unexpected non-page aligned data payload\n");
 		dump_stack();
-		return -1;
+		rc = -1;
+		goto repost;
 	}
 	isert_dbg("Copying DataOut: sg_start: %p, sg_off: %u "
 		  "sg_nents: %u from %p %u\n", sg_start, sg_off,
@@ -1169,13 +1169,18 @@ isert_handle_iscsi_dataout(struct isert_conn *isert_conn,
 
 	rc = iscsit_check_dataout_payload(cmd, hdr, false);
 	if (rc < 0)
-		return rc;
+		goto repost;
 
 	/*
 	 * multiple data-outs on the same command can arrive -
 	 * so post the buffer before hand
 	 */
 	return isert_post_recv(isert_conn, rx_desc);
+
+repost:
+	/* Nothing else owns this Data-Out's receive descriptor. */
+	isert_post_recv(isert_conn, rx_desc);
+	return rc;
 }
 
 static int
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself
  2026-11-16 10:11 [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself Yehyeong Lee
  2026-11-16 10:11 ` [PATCH 2/2] IB/isert: do not leak the receive descriptor of a dropped Data-Out Yehyeong Lee
@ 2026-11-16 10:30 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-16 10:30 UTC (permalink / raw)
  To: Yehyeong Lee; +Cc: linux-rdma, target-devel, linux-scsi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] IB/isert: late or missing isert_cmd init for target-allocated
  commands
--

commit 7a5bd9118f37880c28b788536bd93564bfb3692e
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>

IB/isert: finish a Reject the target core allocated itself

This commit updates isert_post_recv() to ignore commands without a receive
descriptor and initializes isert_cmd->conn and isert_cmd->iscsit_cmd in
isert_put_reject() for reject commands allocated by iscsit_add_reject().

> diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
> index efa8d7b7844c9..81164881dcc24 100644
> --- a/drivers/infiniband/ulp/isert/ib_isert.c
> +++ b/drivers/infiniband/ulp/isert/ib_isert.c
> @@ -758,7 +758,8 @@ isert_post_recv(struct isert_conn *isert_conn, struct iser_rx_desc *rx_desc)
>  	struct ib_recv_wr rx_wr;
>  	int ret;
>  
> -	if (!rx_desc->in_use) {
> +	/* A command iscsit_add_reject() allocated has no descriptor. */
> +	if (!rx_desc || !rx_desc->in_use) {
>  		/*
>  		 * if the descriptor is not in-use we already reposted it
>  		 * for recv, so just silently return
> @@ -1958,6 +1959,9 @@ isert_put_reject(struct iscsit_cmd *cmd, struct iscsit_conn *conn)
>  	struct iscsi_reject *hdr =
>  		(struct iscsi_reject *)&isert_cmd->tx_desc.iscsi_header;
>  
> +	isert_cmd->conn = isert_conn;
> +	isert_cmd->iscsit_cmd = cmd;
> +
>  	isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
>  	iscsit_build_reject(cmd, conn, hdr);
>  	isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);

[Severity: High]
Can a target-allocated command still reach isert_put_cmd() or
isert_send_done() with NULL isert_cmd->conn and isert_cmd->iscsit_cmd?

iscsit_add_reject() links the zeroed command (with targ_xfer_tag == 0) onto
conn->conn_cmd_list before queuing it to the response queue.  If the
initiator sends an immediate NOP-Out with itt == 0xffffffff and ttt == 0,
iscsit_process_nop_out() matches the reject command on conn->conn_cmd_list
and queues it with ISTATE_REMOVE on the immediate queue:

drivers/target/iscsi/iscsi_target.c:iscsit_process_nop_out() {
	...
	if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) {
		cmd_p = iscsit_find_cmd_from_ttt(conn, be32_to_cpu(hdr->ttt));
		if (!cmd_p)
			return -EINVAL;

		iscsit_stop_nopin_response_timer(conn);

		cmd_p->i_state = ISTATE_REMOVE;
		iscsit_add_cmd_to_immediate_queue(cmd_p, conn, cmd_p->i_state);

		iscsit_start_nopin_timer(conn);
		return 0;
	}
	...
}

Because iscsi_target_tx_thread() drains the immediate queue before the
response queue, isert_immediate_queue() calls isert_put_cmd() before
isert_put_reject() has populated isert_cmd->conn and isert_cmd->iscsit_cmd,
causing a NULL pointer dereference (or freeing the command while it remains
queued on conn->response_queue_list).

In addition, both iscsit_process_nop_out() above and
iscsit_na_nopin_timeout() start nopin_timer without checking for
ISCSI_INFINIBAND.  When that timer fires, iscsit_add_nopin() allocates an
unsolicited NOP-In via iscsit_allocate_cmd() and queues it to
isert_immediate_queue() -> isert_put_nopin().  Now that isert_post_recv()
accepts a NULL rx_desc, isert_put_nopin() posts the send work request
without setting isert_cmd->conn or isert_cmd->iscsit_cmd, and
isert_send_done() dereferences a NULL isert_cmd->iscsit_cmd on completion.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116101108.1650132-1-yhlee@isslab.korea.ac.kr?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-16 10:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 10:11 [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself Yehyeong Lee
2026-11-16 10:11 ` [PATCH 2/2] IB/isert: do not leak the receive descriptor of a dropped Data-Out Yehyeong Lee
2026-11-16 10:30 ` [PATCH 1/2] IB/isert: finish a Reject the target core allocated itself sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox