Skip to content

Commit

Permalink
scsi: qla2xxx: Avoid that qlt_send_resp_ctio() corrupts memory
Browse files Browse the repository at this point in the history
The "(&ctio->u.status1.sense_data)[i]" where i >= 0 expressions in
qlt_send_resp_ctio() are probably typos and should have been
"(&ctio->u.status1.sense_data[4 * i])" instead. Instead of only fixing
these typos, modify the code for storing sense data such that it becomes
easy to read. This patch fixes a Coverity complaint about accessing an
array outside its bounds.

Cc: Himanshu Madhani <[email protected]>
Cc: Giridhar Malavali <[email protected]>
Fixes: be25152 ("qla2xxx: Improve T10-DIF/PI handling in driver.") # v4.11.
Signed-off-by: Bart Van Assche <[email protected]>
Acked-by: Himanshu Madhani <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
bvanassche authored and martinkpetersen committed Apr 29, 2019
1 parent 300ec74 commit a861b49
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/scsi/qla2xxx/qla_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -2329,14 +2329,14 @@ void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
ctio->u.status1.scsi_status |=
cpu_to_le16(SS_RESIDUAL_UNDER);

/* Response code and sense key */
put_unaligned_le32(((0x70 << 24) | (sense_key << 8)),
(&ctio->u.status1.sense_data)[0]);
/* Fixed format sense data. */
ctio->u.status1.sense_data[0] = 0x70;
ctio->u.status1.sense_data[2] = sense_key;
/* Additional sense length */
put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]);
ctio->u.status1.sense_data[7] = 0xa;
/* ASC and ASCQ */
put_unaligned_le32(((asc << 24) | (ascq << 16)),
(&ctio->u.status1.sense_data)[3]);
ctio->u.status1.sense_data[12] = asc;
ctio->u.status1.sense_data[13] = ascq;

/* Memory Barrier */
wmb();
Expand Down

0 comments on commit a861b49

Please sign in to comment.