Skip to content

Commit

Permalink
[SCSI] libiscsi: fix senselen calculation
Browse files Browse the repository at this point in the history
Yanling Qi, noted that when the sense data length of
a check-condition is greater than 0x7f (127), senselen = (data[0] << 8)
| data[1] will become negative. It causes different kinds of panics from
GPF, spin_lock deadlock to spin_lock recursion.

We were also swapping this value on big endien machines.

This patch fixes both issues by using be16_to_cpu().

Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
  • Loading branch information
Mike Christie authored and James Bottomley committed Jan 6, 2007
1 parent 94cb3f8 commit 9b80cb4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/scsi/libiscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static int iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
}

if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
int senselen;
uint16_t senselen;

if (datalen < 2) {
invalid_datalen:
Expand All @@ -270,12 +270,12 @@ static int iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
goto out;
}

senselen = (data[0] << 8) | data[1];
senselen = be16_to_cpu(*(uint16_t *)data);
if (datalen < senselen)
goto invalid_datalen;

memcpy(sc->sense_buffer, data + 2,
min(senselen, SCSI_SENSE_BUFFERSIZE));
min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
debug_scsi("copied %d bytes of sense\n",
min(senselen, SCSI_SENSE_BUFFERSIZE));
}
Expand Down

0 comments on commit 9b80cb4

Please sign in to comment.