Skip to content

Commit 9835db3

Browse files
hreineckegregkh
authored andcommitted
scsi_common: do not clobber fixed sense information
commit ba08311647892cc7912de74525fd78416caf544a upstream. For fixed sense the information field is 32 bits, to we need to truncate the information field to avoid clobbering the sense code. Fixes: a1524f2 ("libata-eh: Set 'information' field for autosense") Signed-off-by: Hannes Reinecke <hare@suse.com> Reviewed-by: Lee Duncan <lduncan@suse.com> Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com> Reviewed-by: Ewan D. Milne <emilne@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4cd4ebb commit 9835db3

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/scsi/scsi_common.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,16 @@ int scsi_set_sense_information(u8 *buf, int buf_len, u64 info)
278278
ucp[3] = 0;
279279
put_unaligned_be64(info, &ucp[4]);
280280
} else if ((buf[0] & 0x7f) == 0x70) {
281-
buf[0] |= 0x80;
282-
put_unaligned_be64(info, &buf[3]);
281+
/*
282+
* Only set the 'VALID' bit if we can represent the value
283+
* correctly; otherwise just fill out the lower bytes and
284+
* clear the 'VALID' flag.
285+
*/
286+
if (info <= 0xffffffffUL)
287+
buf[0] |= 0x80;
288+
else
289+
buf[0] &= 0x7f;
290+
put_unaligned_be32((u32)info, &buf[3]);
283291
}
284292

285293
return 0;

0 commit comments

Comments
 (0)