Commit

8ee2a09a1dbb257c9e828ad2497f8e4832dfb142

scsi: libiscsi: Reject a negative task index from parse_pdu_itt

A transport that implements parse_pdu_itt hands libiscsi an index taken
from the PDU, and both lookups bound it from above only:

      if (i >= session->cmds_max)

i and cmds_max are both int, so a negative index passes and
session->cmds[i] is read from before the array.

be2iscsi produces one. beiscsi_parse_pdu() assigns the raw tag,

      *index = (int)itt;

and beiscsi_complete_pdu() forwards an unsolicited NOP-In from the
hardware async ring without replacing its ITT, so the value is the
target's. It also reports the session's own age rather than the one in
the tag, which leaves the age comparison in iscsi_verify_itt() with
nothing to reject.

Bound the index from below in both lookups.

Fixes: bfead3b2cb46 ("[SCSI] be2iscsi: Adding msix and mcc_rings V3")
Cc: stable@vger.kernel.org
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
Link: https://patch.msgid.link/20261007015842.634893-2-yhlee@isslab.korea.ac.kr
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>

Yehyeong Lee <yhlee@isslab.korea.ac.kr> · 2026-10-07 01:58 UTC · committed by Martin K. Petersen (Oracle)

Browse files
1 file changed, +2 −2
modified drivers/scsi/libiscsi.c
@@ -1191,7 +1191,7 @@ struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *conn, itt_t itt)
1191 1191 session->tt->parse_pdu_itt(conn, itt, &i, NULL);
1192 1192 else
1193 1193 i = get_itt(itt);
1194 - if (i >= session->cmds_max)
1194 + if (i < 0 || i >= session->cmds_max)
1195 1195 return NULL;
1196 1196
1197 1197 return session->cmds[i];
@@ -1384,7 +1384,7 @@ int iscsi_verify_itt(struct iscsi_conn *conn, itt_t itt)
1384 1384 return ISCSI_ERR_BAD_ITT;
1385 1385 }
1386 1386
1387 - if (i >= session->cmds_max) {
1387 + if (i < 0 || i >= session->cmds_max) {
1388 1388 iscsi_conn_printk(KERN_ERR, conn,
1389 1389 "received invalid itt index %u (max cmds "
1390 1390 "%u.\n", i, session->cmds_max);