Skip to content

Commit 96e8e26

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: target/iscsi: Only send R2T if needed
If an initiator submits more immediate data than the size derived from the SCSI CDB, do not send any R2T to the initiator. This scenario is triggered by the libiscsi test ALL.iSCSIResiduals.WriteVerify16Residuals if the iSCSI target driver is modified to discard too large immediate data buffers instead of trying to parse these as an iSCSI PDU. This patch avoids that a negative xfer_len value is passed to iscsit_add_r2t_to_list() if too large immediate data buffers are handled correctly. Cc: Mike Christie <mchristi@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Hannes Reinecke <hare@suse.de> Cc: Nicholas Bellinger <nab@linux-iscsi.org> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent b0055ac commit 96e8e26

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎drivers/target/iscsi/iscsi_target.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,6 +3121,12 @@ int iscsit_build_r2ts_for_cmd(
31213121
else
31223122
xfer_len = conn->sess->sess_ops->MaxBurstLength;
31233123
}
3124+
3125+
if ((s32)xfer_len < 0) {
3126+
cmd->cmd_flags |= ICF_SENT_LAST_R2T;
3127+
break;
3128+
}
3129+
31243130
cmd->r2t_offset += xfer_len;
31253131

31263132
if (cmd->r2t_offset == cmd->se_cmd.data_length)

‎drivers/target/iscsi/iscsi_target_util.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ int iscsit_add_r2t_to_list(
6767

6868
lockdep_assert_held(&cmd->r2t_lock);
6969

70+
WARN_ON_ONCE((s32)xfer_len < 0);
71+
7072
r2t = kmem_cache_zalloc(lio_r2t_cache, GFP_ATOMIC);
7173
if (!r2t) {
7274
pr_err("Unable to allocate memory for struct iscsi_r2t.\n");

0 commit comments

Comments
 (0)