Re: [PATCH] scsi: libiscsi_tcp: hold back_lock across the copy of a Data-In
From: Yehyeong Lee
Date: Fri Nov 20 2026 - 11:40:04 EST
On Fri, Nov 20, 2026 at 03:15:55PM +0000, sashiko-bot@xxxxxxxxxx wrote:
> Should iscsi_tcp_hdr_dissect() verify that task->state ==
> ISCSI_TASK_RUNNING before accepting a Data-In header and setting
> tcp_conn->in.datain_task?
>
> iscsi_itt_to_ctask() only checks task->sc and session->age, so it also
> returns newly queued commands in ISCSI_TASK_PENDING on conn->cmdqueue.
It already does, in the series this patch follows up on: 3/4 makes
iscsi_itt_to_ctask() return NULL for ISCSI_TASK_PENDING and
ISCSI_TASK_FREE, and 4/4 adds the task->state != ISCSI_TASK_RUNNING test
to the ISCSI_OP_SCSI_DATA_IN arm of iscsi_tcp_hdr_dissect(). Against
plain mainline the PENDING case is real, but it predates this patch.
https://lore.kernel.org/r/20261117101500.1894608-4-yhlee@xxxxxxxxxxxxxxxxxx
https://lore.kernel.org/r/20261117101500.1894608-5-yhlee@xxxxxxxxxxxxxxxxxx
> Can dropping session->back_lock before segment->done() let
> iscsi_tcp_process_data_in() complete a newly queued command that reuses
> the freed ITT slot?
[...]
> digests are enabled, iscsi_tcp_segment_splice_digest() sets
> segment->sg = NULL before receiving the 4-byte digest, so a subsequent skb
> carrying the digest skips the if (segment->sg) check and reaches
> segment->done() after the task was already freed.
No. iscsi_tcp_process_data_in() never touches segment->sg: it verifies
the digest and, for ISCSI_FLAG_DATA_STATUS, calls iscsi_complete_pdu(),
which takes back_lock itself and completes through __iscsi_complete_pdu()
like any other PDU; a task in ISCSI_TASK_PENDING is refused there by 3/4.
That a target can send status for an ITT whose command has been
transmitted is not new. The digest path is the same answer: after the
splice, segment->data is the four-byte digest buffer, so the copy that
skips the test goes nowhere near the scatterlist.
> Does unlocking session->back_lock at skb_done leave segment->sg_mapped
> mapped with kmap_atomic()?
[...]
> spin_lock_bh(&session->back_lock) while inside kmap_atomic() /
> pagefault_disable() (which violates sleeping spinlock rules on
> CONFIG_PREEMPT_RT).
Not a problem, on either half. On CONFIG_PREEMPT_RT kmap_atomic() does
migrate_disable() and pagefault_disable() rather than preempt_disable()
(include/linux/highmem-internal.h), so a spinlock_t may be taken under
it. And a mapping of a page that has since been freed is not
dereferenced: the next skb hits the segment->sg test first, finds
datain_task gone and fails the connection before any copy, and
iscsi_sw_tcp_recv_data() tears the mapping down once tcp_read_sock()
returns.
> Does the conditional locking across copy_locked trigger a Clang
> -Wthread-safety-analysis warning when CONFIG_WARN_CONTEXT_ANALYSIS=y?
Correct, three of them, fixed in v2. clang 23.1.6 with
CONFIG_WARN_CONTEXT_ANALYSIS=y gives one "spinlock
'conn->session->back_lock' is not held on every path through here" and
two "releasing spinlock 'conn->session->back_lock' that was not held" on
v1. v2 moves the copy into a helper so the lock is taken and released on
one path, and the file builds clean.
https://lore.kernel.org/all/20261120163857.3238489-1-yhlee@xxxxxxxxxxxxxxxxxx/
Best regards,
Yehyeong Lee