Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v4 scsi-fixes 1/2] scsi: target: iscsi: Reserve tags on standalone Rejects
@ 2026-12-02 16:49 Andrew Stellman
  2026-12-02 16:49 ` [PATCH v4 scsi-fixes 2/2] scsi: target: iscsi: Fix UAF on an immediate data digest error Andrew Stellman
  2026-12-02 17:03 ` [PATCH v4 scsi-fixes 1/2] scsi: target: iscsi: Reserve tags on standalone Rejects sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Stellman @ 2026-12-02 16:49 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: Mike Christie, target-devel, linux-scsi

From: Andrew Stellman <astellman@stellman-greene.com>

iscsit_add_reject() allocates a zeroed command, so a Reject's ITT and
TTT are both 0 while it waits on conn_cmd_list for its StatSN to be
acknowledged. After an oversized Data-Out gets such a Reject (the
connection stays up), a NOP-Out with ITT 0xffffffff and TTT 0 matches it
in iscsit_find_cmd_from_ttt(), and iscsit_process_nop_out() queues it as
ISTATE_REMOVE, so the TX thread frees the Reject header before sending
it:

  ==================================================================
  BUG: KASAN: slab-use-after-free in _copy_from_iter+0x770/0x10d0
  Read of size 48 at addr ffff0000e8094780 by task iscsi_ttx/381

  CPU: 0 UID: 0 PID: 381 Comm: iscsi_ttx Not tainted 7.4.0-rc4 #1 PREEMPT(full)
  Hardware name: linux,dummy-virt (DT)
  Call trace:
   show_stack+0x18/0x24 (C)
   dump_stack_lvl+0x60/0x80
   print_report+0x17c/0x4d8
   kasan_report+0xbc/0x124
   kasan_check_range+0x100/0x1a8
   __asan_memcpy+0x3c/0xa0
   _copy_from_iter+0x770/0x10d0
   tcp_sendmsg_locked+0x16dc/0x33dc
   tcp_sendmsg+0x38/0x60
   inet_sendmsg+0x90/0xdc
   sock_sendmsg+0x144/0x228
   tx_data+0x140/0x1e8
   iscsit_send_tx_data+0xb0/0x198
   iscsit_xmit_pdu+0x62c/0xbb8
   iscsit_response_queue+0xa84/0x1340
   iscsi_target_tx_thread+0x404/0x460
   kthread+0x36c/0x420
   ret_from_fork+0x10/0x20

  Allocated by task 382:
   kasan_save_stack+0x3c/0x70
   kasan_save_track+0x20/0x4c
   kasan_save_alloc_info+0x40/0x60
   __kasan_kmalloc+0xb8/0xbc
   __kmalloc_node_track_caller_noprof+0x1b0/0x458
   kmemdup_noprof+0x34/0x60
   iscsit_add_reject+0x94/0x210
   iscsit_check_dataout_hdr+0x294/0x350
   iscsit_get_rx_pdu+0x3d4/0x24a0
   iscsi_target_rx_thread+0x110/0x260
   kthread+0x36c/0x420
   ret_from_fork+0x10/0x20

  Freed by task 381:
   kasan_save_stack+0x3c/0x70
   kasan_save_track+0x20/0x4c
   kasan_save_free_info+0x4c/0x80
   __kasan_slab_free+0x78/0xa4
   kfree+0x124/0x410
   iscsit_release_cmd+0xbc/0x2c8
   iscsit_free_cmd+0x100/0x14c
   iscsit_immediate_queue+0x104/0x8ac
   iscsi_target_tx_thread+0x340/0x460
   kthread+0x36c/0x420
   ret_from_fork+0x10/0x20

  The buggy address belongs to the object at ffff0000e8094780
   which belongs to the cache kmalloc-64 of size 64
  The buggy address is located 0 bytes inside of
   freed 64-byte region [ffff0000e8094780, ffff0000e80947c0)

  The buggy address belongs to the physical page:
  page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x128094
  flags: 0xbfffe0000000000(node=0|zone=2|lastcpupid=0x1ffff)
  page_type: f5(slab)
  raw: 0bfffe0000000000 ffff0000c00028c0 dead000000000122 0000000000000000
  raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
  page dumped because: kasan: bad access detected

  Memory state around the buggy address:
   ffff0000e8094680: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
   ffff0000e8094700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
  >ffff0000e8094780: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                     ^
   ffff0000e8094800: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
   ffff0000e8094880: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
  ==================================================================

Set the Reject's ITT to RESERVED_ITT and its TTT to 0xffffffff, as
iscsit_add_nopin() does. This changes existing behaviour for every
iscsit_add_reject() caller.

Fixes: 561bf1589237 ("iscsi-target: Fix iscsit_sequence_cmd reject handling for iser")
Cc: stable@vger.kernel.org
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v3: https://lore.kernel.org/r/20261129155252.2217-1-bugs@stellman-greene.com/
v2: https://lore.kernel.org/target-devel/20261129001755.78909-1-bugs@stellman-greene.com/
Tested in arm64 QEMU with KASAN and a test-only 100 ms delay in the TX
thread: without this patch KASAN reported the above, and with it there
was no KASAN, refcount or WARNING report.
Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook) running Claude Opus
5.5; the fix was drafted with OpenAI GPT-6 (Codex).
A reproducer is available on request.

 drivers/target/iscsi/iscsi_target.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 2b4956f46c132..359c66d1051ab 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -797,6 +797,8 @@ int iscsit_add_reject(
 
 	cmd->iscsi_opcode = ISCSI_OP_REJECT;
 	cmd->reject_reason = reason;
+	cmd->init_task_tag = RESERVED_ITT;
+	cmd->targ_xfer_tag = 0xFFFFFFFF;
 
 	cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL);
 	if (!cmd->buf_ptr) {
-- 
2.53.0


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

end of thread, other threads:[~2026-12-02 17:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 16:49 [PATCH v4 scsi-fixes 1/2] scsi: target: iscsi: Reserve tags on standalone Rejects Andrew Stellman
2026-12-02 16:49 ` [PATCH v4 scsi-fixes 2/2] scsi: target: iscsi: Fix UAF on an immediate data digest error Andrew Stellman
2026-12-02 17:03 ` [PATCH v4 scsi-fixes 1/2] scsi: target: iscsi: Reserve tags on standalone Rejects sashiko-bot

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