linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yehyeong Lee" <yhlee@isslab.korea.ac.kr>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: libiscsi: validate the ITT reflected in a Reject PDU
Date: Mon, 03 Aug 2026 11:07:25 +0000	[thread overview]
Message-ID: <20260803110726.45F781F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803104149.2114414-1-yhlee@isslab.korea.ac.kr>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [High] The newly added task validation logic in `iscsi_handle_reject` introduces a Time-of-Check to Time-of-Use (TOCTOU) data race against concurrent task allocation.

Pre-existing issues:
- [Critical] The vulnerability preventing malicious target completion of in-flight SCSI commands or free tasks is only patched for `ISCSI_OP_REJECT`, leaving other management opcodes vulnerable to the exact same exploit.
- [Critical] Negative ITT values bypass bounds checking when using drivers like be2iscsi, leading to an out-of-bounds array access on the session cmds array.
- [High] The patch prevents spoofed Reject PDUs from erroneously completing SCSI tasks by checking `!task->sc`, but leaves non-SCSI management tasks (e.g., TMFs, Logout) vulnerable to a double-completion exploit via reallocation.
--

--- Patch [1]: [PATCH] scsi: libiscsi: validate the ITT reflected in a Reject PDU ---
commit bf6ef027cf2ac528cf92e9e76e0a750fc88ecc70
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
Subject: scsi: libiscsi: validate the ITT reflected in a Reject PDU

This commit addresses an issue where an invalid ITT in a Reject PDU could
cause a null pointer dereference or complete an active task incorrectly.
It adds a check in iscsi_handle_reject to verify the ITT and ensure the
task is valid and is a SCSI command before cleaning it up.

> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
> index 6bffd91b973a4..23ae038c54820 100644
> --- a/drivers/scsi/libiscsi.c
> +++ b/drivers/scsi/libiscsi.c
> @@ -1089,8 +1089,11 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
>  			 * Our nop as ping got dropped. We know the target
>  			 * and transport are ok so just clean up
>  			 */
> -			task = iscsi_itt_to_task(conn, rejected_pdu.itt);
> -			if (!task) {
> +			task = NULL;
> +			if (!iscsi_verify_itt(conn, rejected_pdu.itt))

[Severity: Critical]
This isn't a bug introduced by this patch, but does the new call to
iscsi_verify_itt() properly handle negative ITT values?

When using drivers like be2iscsi, the network ITT is cast to a signed
integer:

drivers/scsi/be2iscsi/be_main.c:beiscsi_parse_pdu() {
    ...
    *index = (int)itt;
    ...
}

In iscsi_verify_itt() and iscsi_itt_to_task(), the bounds check performs a
signed comparison:

    if (i >= session->cmds_max) {

If an ITT with the MSB set (e.g., 0x80000000) is provided, would this
evaluate to false for negative integers and completely bypass the bounds
check, allowing an out-of-bounds access on session->cmds[i]?

> +				task = iscsi_itt_to_task(conn, rejected_pdu.itt);
> +			if (!task || task->state == ISCSI_TASK_FREE ||
> +			    task->sc) {

[Severity: High]
Does this unprotected lockless read introduce a Time-of-Check to Time-of-Use
(TOCTOU) data race against concurrent task allocation?

Looking at iscsi_alloc_task(), which runs under frwd_lock, it assigns
task->state before setting task->sc without any memory barriers:

iscsi_alloc_task() {
    ...
    task->state = ISCSI_TASK_PENDING;
    task->conn = conn;
    task->sc = sc;
    ...
}

The RX softirq thread here in iscsi_handle_reject() checks task->state and
task->sc without holding the frwd_lock. If a Reject PDU arrives exactly as a
task is allocated, could the RX thread observe task->state ==
ISCSI_TASK_PENDING and task->sc == NULL, causing this check to evaluate to
false and prematurely complete the task via iscsi_nop_out_rsp()?

[Severity: High]
This is a pre-existing issue, but does this logic leave non-NOOP management
tasks vulnerable to a double-completion exploit?

Since TMF tasks are allocated from cmdpool but have task->sc == NULL, this
new check evaluates to false for an in-flight non-SCSI management task
(like an Abort TMF).

If a target sends a spoofed Reject PDU with the ITT of an in-flight TMF
task, could iscsi_nop_out_rsp() prematurely complete and free it?
Consequently, if the initiator reallocates this freed task for a legitimate
SCSI command and the target finally sends the actual response for the
original TMF, would the new SCSI command be prematurely completed?

>  				iscsi_conn_printk(KERN_ERR, conn,
>  						 "Invalid pdu reject. Could "
>  						 "not lookup rejected task.\n");

[Severity: Critical]
This is a pre-existing issue, but is this vulnerability also present for
other management opcodes?

While this patch addresses ISCSI_OP_REJECT, __iscsi_complete_pdu() fetches
the task for other management response opcodes without validating if it is a
free task or an active SCSI command:

__iscsi_complete_pdu() {
    ...
    case ISCSI_OP_LOGOUT_RSP:
    case ISCSI_OP_LOGIN_RSP:
    case ISCSI_OP_TEXT_RSP:
    case ISCSI_OP_SCSI_TMFUNC_RSP:
    case ISCSI_OP_NOOP_IN:
        task = iscsi_itt_to_task(conn, hdr->itt);
    ...
}

If a target sends a management response containing the ITT of a free task or
an active SCSI command, could it completely bypass this patch's logic and
be erroneously passed to completion functions?

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

      reply	other threads:[~2026-08-03 11:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 10:41 [PATCH] scsi: libiscsi: validate the ITT reflected in a Reject PDU Yehyeong Lee
2026-08-03 11:07 ` sashiko-bot [this message]

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=20260803110726.45F781F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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;
as well as URLs for NNTP newsgroup(s).