diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index e8c41d0c1b93..3da5e7d5baf6 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -5362,7 +5362,8 @@ ctl_sync_cache(struct ctl_scsiio *ctsio) * to see an error for an out of range LBA. */ if ((starting_lba + block_count) > (lun->be_lun->maxlba + 1)) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, + MAX(starting_lba, lun->be_lun->maxlba + 1)); ctl_done((union ctl_io *)ctsio); goto bailout; } @@ -5678,7 +5679,8 @@ ctl_write_same(struct ctl_scsiio *ctsio) */ if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) || ((lba + num_blocks) < lba)) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, + MAX(lba, lun->be_lun->maxlba + 1)); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); } @@ -5791,7 +5793,8 @@ ctl_unmap(struct ctl_scsiio *ctsio) num_blocks = scsi_4btoul(range->length); if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) || ((lba + num_blocks) < lba)) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, + MAX(lba, lun->be_lun->maxlba + 1)); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); } @@ -6995,7 +6998,7 @@ ctl_get_lba_status(struct ctl_scsiio *ctsio) alloc_len = scsi_4btoul(cdb->alloc_len); if (lba > lun->be_lun->maxlba) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, lba); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); } @@ -8785,7 +8788,8 @@ ctl_read_write(struct ctl_scsiio *ctsio) */ if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) || ((lba + num_blocks) < lba)) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, + MAX(lba, lun->be_lun->maxlba + 1)); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); } @@ -8894,7 +8898,8 @@ ctl_cnw(struct ctl_scsiio *ctsio) */ if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) || ((lba + num_blocks) < lba)) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, + MAX(lba, lun->be_lun->maxlba + 1)); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); } @@ -9005,7 +9010,8 @@ ctl_verify(struct ctl_scsiio *ctsio) */ if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) || ((lba + num_blocks) < lba)) { - ctl_set_lba_out_of_range(ctsio); + ctl_set_lba_out_of_range(ctsio, + MAX(lba, lun->be_lun->maxlba + 1)); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); } diff --git a/sys/cam/ctl/ctl_error.c b/sys/cam/ctl/ctl_error.c index 5bdaf08b299e..4f839dbf2662 100644 --- a/sys/cam/ctl/ctl_error.c +++ b/sys/cam/ctl/ctl_error.c @@ -181,8 +181,8 @@ ctl_sense_to_desc(struct scsi_sense_data_fixed *sense_src, /*asc*/ sense_src->add_sense_code, /*ascq*/ sense_src->add_sense_code_qual, - /* Information Bytes */ - (scsi_4btoul(sense_src->info) != 0) ? + /* Information Bytes */ + (sense_src->error_code & SSD_ERRCODE_VALID) ? SSD_ELEM_INFO : SSD_ELEM_SKIP, sizeof(sense_src->info), sense_src->info, @@ -727,14 +727,20 @@ ctl_set_aborted(struct ctl_scsiio *ctsio) } void -ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio) +ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio, uint64_t lba) { + uint8_t info[8]; + + scsi_u64to8b(lba, info); + /* "Logical block address out of range" */ ctl_set_sense(ctsio, /*current_error*/ 1, /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, /*asc*/ 0x21, /*ascq*/ 0x00, + /*type*/ (lba != 0) ? SSD_ELEM_INFO : SSD_ELEM_SKIP, + /*size*/ sizeof(info), /*data*/ &info, SSD_ELEM_NONE); } diff --git a/sys/cam/ctl/ctl_error.h b/sys/cam/ctl/ctl_error.h index 98706438e567..192228977896 100644 --- a/sys/cam/ctl/ctl_error.h +++ b/sys/cam/ctl/ctl_error.h @@ -76,7 +76,7 @@ void ctl_set_internal_failure(struct ctl_scsiio *ctsio, int sks_valid, uint16_t retry_count); void ctl_set_medium_error(struct ctl_scsiio *ctsio, int read); void ctl_set_aborted(struct ctl_scsiio *ctsio); -void ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio); +void ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio, uint64_t lba); void ctl_set_lun_stopped(struct ctl_scsiio *ctsio); void ctl_set_lun_int_reqd(struct ctl_scsiio *ctsio); void ctl_set_lun_ejected(struct ctl_scsiio *ctsio); diff --git a/sys/cam/ctl/ctl_tpc.c b/sys/cam/ctl/ctl_tpc.c index bebaccff6315..8efff1704138 100644 --- a/sys/cam/ctl/ctl_tpc.c +++ b/sys/cam/ctl/ctl_tpc.c @@ -1104,7 +1104,8 @@ tpc_ranges_length(struct scsi_range_desc *range, int nrange) } static int -tpc_check_ranges_l(struct scsi_range_desc *range, int nrange, uint64_t maxlba) +tpc_check_ranges_l(struct scsi_range_desc *range, int nrange, uint64_t maxlba, + uint64_t *lba) { uint64_t b1; uint32_t l1; @@ -1113,8 +1114,10 @@ tpc_check_ranges_l(struct scsi_range_desc *range, int nrange, uint64_t maxlba) for (i = 0; i < nrange; i++) { b1 = scsi_8btou64(range[i].lba); l1 = scsi_4btoul(range[i].length); - if (b1 + l1 < b1 || b1 + l1 > maxlba + 1) + if (b1 + l1 < b1 || b1 + l1 > maxlba + 1) { + *lba = MAX(b1, maxlba + 1); return (-1); + } } return (0); } @@ -1952,6 +1955,7 @@ ctl_populate_token(struct ctl_scsiio *ctsio) struct ctl_port *port; struct tpc_list *list, *tlist; struct tpc_token *token; + uint64_t lba; int len, lendata, lendesc; CTL_DEBUG_PRINT(("ctl_populate_token\n")); @@ -2032,8 +2036,8 @@ ctl_populate_token(struct ctl_scsiio *ctsio) if (tpc_check_ranges_l(&data->desc[0], scsi_2btoul(data->range_descriptor_length) / sizeof(struct scsi_range_desc), - lun->be_lun->maxlba) != 0) { - ctl_set_lba_out_of_range(ctsio); + lun->be_lun->maxlba, &lba) != 0) { + ctl_set_lba_out_of_range(ctsio, lba); goto done; } if (tpc_check_ranges_x(&data->desc[0], @@ -2118,6 +2122,7 @@ ctl_write_using_token(struct ctl_scsiio *ctsio) struct ctl_lun *lun; struct tpc_list *list, *tlist; struct tpc_token *token; + uint64_t lba; int len, lendata, lendesc; CTL_DEBUG_PRINT(("ctl_write_using_token\n")); @@ -2180,8 +2185,8 @@ ctl_write_using_token(struct ctl_scsiio *ctsio) if (tpc_check_ranges_l(&data->desc[0], scsi_2btoul(data->range_descriptor_length) / sizeof(struct scsi_range_desc), - lun->be_lun->maxlba) != 0) { - ctl_set_lba_out_of_range(ctsio); + lun->be_lun->maxlba, &lba) != 0) { + ctl_set_lba_out_of_range(ctsio, lba); goto done; } if (tpc_check_ranges_x(&data->desc[0],