From: sashiko-bot@kernel.org
To: "Yehyeong Lee" <yhlee@isslab.korea.ac.kr>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 4/4] scsi: libiscsi_tcp: do not accept a Data-In for a finished command
Date: Tue, 17 Nov 2026 10:40:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-218654@kernel.org> (raw)
In-Reply-To: <20261117101500.1894608-5-yhlee@isslab.korea.ac.kr>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] scsi: libiscsi_tcp: UAF in iscsi_tcp_segment_done() after TMF
response
- [Medium] scsi: libiscsi: incomplete task state check in
__iscsi_complete_pdu()
--
commit 9af7de9bba715ed5449c628822a2ee292f1c78ed
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
scsi: libiscsi_tcp: do not accept a Data-In for a finished command
This commit rejects incoming Data-In PDUs in iscsi_tcp_hdr_dissect() when
the command task is not running and rejects completed tasks in
__iscsi_complete_pdu().
> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
> index af454454c0869..f8b3b597d0154 100644
> --- a/drivers/scsi/libiscsi.c
> +++ b/drivers/scsi/libiscsi.c
> @@ -1312,7 +1312,7 @@ int __iscsi_complete_pdu(struct iscsi_session *session, struct iscsi_conn *conn,
> case ISCSI_OP_SCSI_CMD_RSP:
> case ISCSI_OP_SCSI_DATA_IN:
> task = iscsi_itt_to_ctask(session, conn, hdr->itt);
> - if (!task)
> + if (!task || task->state == ISCSI_TASK_COMPLETED)
> return ISCSI_ERR_BAD_ITT;
> task->last_xfer = jiffies;
> break;
[Severity: Medium]
Should this test task->state != ISCSI_TASK_RUNNING rather than only
ISCSI_TASK_COMPLETED?
iscsi_complete_task() also treats ISCSI_TASK_ABRT_TMF,
ISCSI_TASK_ABRT_SESS_RECOV, and ISCSI_TASK_REQUEUE_SCSIQ as terminal
states:
drivers/scsi/libiscsi.c:iscsi_complete_task() {
if (task->state == ISCSI_TASK_COMPLETED ||
task->state == ISCSI_TASK_ABRT_TMF ||
task->state == ISCSI_TASK_ABRT_SESS_RECOV ||
task->state == ISCSI_TASK_REQUEUE_SCSIQ)
return;
When iscsi_eh_abort() calls fail_scsi_task(session, task, DID_ABORT),
__fail_scsi_task() sets sc->result = DID_ABORT << 16 and transitions
task->state to ISCSI_TASK_ABRT_TMF, while the extra task reference held by
iscsi_eh_abort() keeps task->sc live across spin_unlock_bh(&session->frwd_lock).
A late ISCSI_OP_SCSI_CMD_RSP arriving in that window passes this check and
runs iscsi_scsi_cmd_rsp(), overwriting sc->result with
(DID_OK << 16) | rhdr->cmd_status, writing sc->sense_buffer, and updating
the residual count before iscsi_complete_task() ignores the duplicate and
iscsi_put_task() hands the command back via scsi_done().
> diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c
> index 20ec3ba45067f..eeb853c6b66d4 100644
> --- a/drivers/scsi/libiscsi_tcp.c
> +++ b/drivers/scsi/libiscsi_tcp.c
> @@ -713,7 +713,8 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
> case ISCSI_OP_SCSI_DATA_IN:
> spin_lock(&session->back_lock);
> task = iscsi_itt_to_ctask(session, conn, hdr->itt);
> - if (!task)
> + /* The copy below outlives back_lock, so the command must be live. */
> + if (!task || task->state != ISCSI_TASK_RUNNING)
> rc = ISCSI_ERR_BAD_ITT;
> else
> rc = iscsi_tcp_data_in(conn, task);
[Severity: High]
Can tcp_conn->in.segment still dereference a freed scatterlist if a split
Data-In arrives right after a TMF response?
Unlike a SCSI Command Response, receiving ISCSI_OP_SCSI_TMFUNC_RSP in
iscsi_tmf_rsp() only sets session->tmf_state = TMF_SUCCESS and wakes
session->ehwait; it does not change the affected task's state under
session->back_lock. The task remains in ISCSI_TASK_RUNNING until the EH
thread wakes up and runs fail_scsi_task() or fail_scsi_tasks(), which does
not suspend RX or reset tcp_conn->in.segment:
<softirq> (RX) SCSI EH thread
__iscsi_complete_pdu()
iscsi_tmf_rsp()
session->tmf_state = TMF_SUCCESS
wake_up(&session->ehwait)
iscsi_tcp_hdr_dissect() (skb 1)
task->state == ISCSI_TASK_RUNNING
iscsi_segment_seek_sg(...,
sdb->table.sgl, ...)
spin_unlock(&session->back_lock)
iscsi_eh_abort()
fail_scsi_task(..., DID_ABORT)
iscsi_put_task(task)
iscsi_free_task()
scsi_done(sc) -> frees sgl
iscsi_tcp_recv_skb() (skb 2)
iscsi_tcp_segment_done()
accesses tcp_conn->in.segment.sg <-- use-after-free
When the second skb of the Data-In arrives, iscsi_tcp_segment_done() reads
the freed scatterlist and copies payload data into freed pages.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117101500.1894608-1-yhlee@isslab.korea.ac.kr?part=4
next prev parent reply other threads:[~2026-11-17 10:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:14 [PATCH v4 0/4] scsi: libiscsi: tighten task completion Yehyeong Lee
2026-11-17 10:14 ` [PATCH v4 1/4] scsi: libiscsi: only complete a task that has been sent Yehyeong Lee
2026-11-17 10:14 ` [PATCH v4 2/4] scsi: libiscsi: do not complete a task sent with a reserved ITT Yehyeong Lee
2026-11-17 10:14 ` [PATCH v4 3/4] scsi: libiscsi: take a transmit reference before a task is published Yehyeong Lee
2026-11-17 10:15 ` [PATCH v4 4/4] scsi: libiscsi_tcp: do not accept a Data-In for a finished command Yehyeong Lee
2026-11-17 10:40 ` sashiko-bot [this message]
2026-11-17 11:50 ` Yehyeong Lee
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-218654@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