Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yehyeong Lee" <yhlee@isslab.korea.ac.kr>
Cc: linux-rdma@vger.kernel.org, target-devel@vger.kernel.org,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 1/4] scsi: target: iscsi: retire an unsolicited NOP-In only once
Date: Wed, 18 Nov 2026 21:29:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-221994@kernel.org> (raw)
In-Reply-To: <20261118211503.2526705-2-yhlee@isslab.korea.ac.kr>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] scsi: target: iscsi: race on unsent NOP-In in
  iscsit_take_nopin_from_ttt()
--

commit 079f94c5aa78a5118ce1f2b2658476b66fcf7998
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>

scsi: target: iscsi: retire an unsolicited NOP-In only once

This commit introduces iscsit_take_nopin_from_ttt() to match unsolicited
NOP-In commands by opcode and TTT under conn->cmd_lock and clear their tag
so a NOP-In cannot be queued for removal more than once.

Link: https://lore.kernel.org/all/1437516477-30554-4-git-send-email-sbaugh@catern.com/

> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 124ff269b8e75..b0dd3e84e68e0 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -1783,6 +1783,33 @@ int iscsit_setup_nop_out(struct iscsit_conn *conn, struct iscsit_cmd *cmd,
>  }
>  EXPORT_SYMBOL(iscsit_setup_nop_out);
>  
> +/*
> + * Take the NOP-In under cmd_lock, which the tx thread holds when it unlinks
> + * and frees the command, and clear its tag so only the first answer gets it.
> + */
> +static struct iscsit_cmd *iscsit_take_nopin_from_ttt(struct iscsit_conn *conn,
> +						     u32 targ_xfer_tag)
> +{
> +	struct iscsit_cmd *cmd;
> +
> +	spin_lock_bh(&conn->cmd_lock);
> +	list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) {
> +		if (cmd->iscsi_opcode != ISCSI_OP_NOOP_IN ||
> +		    cmd->targ_xfer_tag != targ_xfer_tag)
> +			continue;
> +
> +		cmd->targ_xfer_tag = 0xFFFFFFFF;
> +		cmd->i_state = ISTATE_REMOVE;
> +		spin_unlock_bh(&conn->cmd_lock);
> +		return cmd;
> +	}

[Severity: High]
Can iscsit_take_nopin_from_ttt() claim an unsolicited NOP-In before
iscsit_add_nopin() has queued it or before the TX thread has built and
sent it?

session_get_next_ttt() assigns sequential TTTs, and iscsit_add_nopin()
drops conn->cmd_lock after adding cmd to conn->conn_cmd_list, before
starting nopin_response_timer and queuing ISTATE_SEND_NOPIN_WANT_RESPONSE:

<softirq>                              rx_thread / tx_thread
iscsit_handle_nopin_timeout()
  iscsit_add_nopin()
    spin_lock_bh(&conn->cmd_lock)
    list_add_tail(..., &conn->conn_cmd_list)
    spin_unlock_bh(&conn->cmd_lock)
                                       iscsit_process_nop_out()
                                         iscsit_take_nopin_from_ttt()
                                           cmd->targ_xfer_tag = 0xFFFFFFFF
                                         iscsit_stop_nopin_response_timer()
                                         iscsit_add_cmd_to_immediate_queue(
                                           ..., ISTATE_REMOVE)
    iscsit_start_nopin_response_timer()
    iscsit_add_cmd_to_immediate_queue(
      ..., ISTATE_SEND_NOPIN_WANT_RESPONSE)
                                       iscsit_immediate_queue()
                                         case ISTATE_REMOVE:
                                           iscsit_free_cmd(cmd, false)
                                         case ISTATE_SEND_NOPIN_WANT_RESPONSE:
                                           iscsit_send_unsolicited_nopin(cmd)
                                             <-- use-after-free

Because iscsit_free_cmd(cmd, false) does not purge remaining immediate
queue entries for cmd, the subsequent ISTATE_SEND_NOPIN_WANT_RESPONSE
entry runs on a freed (and potentially reallocated) command slot while
leaving nopin_response_timer running.

Even when ISTATE_SEND_NOPIN_WANT_RESPONSE is queued before the NOP-Out is
processed, if iscsit_take_nopin_from_ttt() runs before the TX thread
executes iscsit_build_nopin_rsp(), overwriting cmd->targ_xfer_tag with
0xFFFFFFFF causes the outgoing unsolicited NOP-In PDU to be transmitted
with hdr->ttt set to 0xFFFFFFFF.

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

  reply	other threads:[~2026-11-18 21:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 21:14 [PATCH v3 0/4] isert: the commands the target core allocates itself Yehyeong Lee
2026-11-18 21:15 ` [PATCH v3 1/4] scsi: target: iscsi: retire an unsolicited NOP-In only once Yehyeong Lee
2026-11-18 21:29   ` sashiko-bot [this message]
2026-11-18 21:15 ` [PATCH v3 2/4] scsi: target: iscsi: do not arm the nopin timer on an iSER connection Yehyeong Lee
2026-11-18 21:25   ` sashiko-bot
2026-11-18 21:15 ` [PATCH v3 3/4] IB/isert: finish a Reject the target core allocated itself Yehyeong Lee
2026-11-18 21:23   ` sashiko-bot
2026-11-18 21:15 ` [PATCH v3 4/4] IB/isert: do not leak the receive descriptor of a dropped Data-Out Yehyeong Lee
2026-11-18 21:28   ` 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=sashiko-outbox-221994@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=target-devel@vger.kernel.org \
    --cc=yhlee@isslab.korea.ac.kr \
    /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