Commit 366c246d authored by James Bottomley's avatar James Bottomley

[SCSI] sd: handle bad lba in sense information

Some devices report medium error locations incorrectly.  Add guards to
make sure the reported bad lba is actually in the request that caused
it.  Additionally remove the large case statment for sector sizes and
replace it with the proper u64 divisions.
Tested-by: default avatarMike Snitzer <snitzer@gmail.com>
Cc: Stable Tree <stable@kernel.org>
Cc: Tony Battersby <tonyb@cybernetics.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent d7402cd9
...@@ -929,6 +929,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) ...@@ -929,6 +929,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
unsigned int xfer_size = scsi_bufflen(SCpnt); unsigned int xfer_size = scsi_bufflen(SCpnt);
unsigned int good_bytes = result ? 0 : xfer_size; unsigned int good_bytes = result ? 0 : xfer_size;
u64 start_lba = SCpnt->request->sector; u64 start_lba = SCpnt->request->sector;
u64 end_lba = SCpnt->request->sector + (xfer_size / 512);
u64 bad_lba; u64 bad_lba;
struct scsi_sense_hdr sshdr; struct scsi_sense_hdr sshdr;
int sense_valid = 0; int sense_valid = 0;
...@@ -967,26 +968,23 @@ static int sd_done(struct scsi_cmnd *SCpnt) ...@@ -967,26 +968,23 @@ static int sd_done(struct scsi_cmnd *SCpnt)
goto out; goto out;
if (xfer_size <= SCpnt->device->sector_size) if (xfer_size <= SCpnt->device->sector_size)
goto out; goto out;
switch (SCpnt->device->sector_size) { if (SCpnt->device->sector_size < 512) {
case 256: /* only legitimate sector_size here is 256 */
start_lba <<= 1; start_lba <<= 1;
break; end_lba <<= 1;
case 512: } else {
break; /* be careful ... don't want any overflows */
case 1024: u64 factor = SCpnt->device->sector_size / 512;
start_lba >>= 1; do_div(start_lba, factor);
break; do_div(end_lba, factor);
case 2048:
start_lba >>= 2;
break;
case 4096:
start_lba >>= 3;
break;
default:
/* Print something here with limiting frequency. */
goto out;
break;
} }
if (bad_lba < start_lba || bad_lba >= end_lba)
/* the bad lba was reported incorrectly, we have
* no idea where the error is
*/
goto out;
/* This computation should always be done in terms of /* This computation should always be done in terms of
* the resolution of the device's medium. * the resolution of the device's medium.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment