summaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorRoland Dreier <roland@purestorage.com>2012-07-17 00:34:22 +0200
committerNicholas Bellinger <nab@linux-iscsi.org>2012-07-17 02:35:35 +0200
commit2594e29865c291db162313187612cd9f14538f33 (patch)
tree731fc047cfaa1965a920d1f48206da8af46a9a2c /drivers/target
parenttarget: Add generation of LOGICAL BLOCK ADDRESS OUT OF RANGE (diff)
downloadlinux-2594e29865c291db162313187612cd9f14538f33.tar.xz
linux-2594e29865c291db162313187612cd9f14538f33.zip
target: Add range checking to UNMAP emulation
When processing an UNMAP command, we need to make sure that the number of blocks we're asked to UNMAP does not exceed our reported maximum number of blocks per UNMAP, and that the range of blocks we're unmapping doesn't go past the end of the device. Signed-off-by: Roland Dreier <roland@purestorage.com> Cc: stable@vger.kernel.org Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r--drivers/target/target_core_iblock.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 8a12e29009c1..8fb3822bad55 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -348,6 +348,18 @@ static int iblock_execute_unmap(struct se_cmd *cmd)
pr_debug("UNMAP: Using lba: %llu and range: %u\n",
(unsigned long long)lba, range);
+ if (range > dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count) {
+ cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST;
+ ret = -EINVAL;
+ goto err;
+ }
+
+ if (lba + range > dev->transport->get_blocks(dev) + 1) {
+ cmd->scsi_sense_reason = TCM_ADDRESS_OUT_OF_RANGE;
+ ret = -EINVAL;
+ goto err;
+ }
+
ret = blkdev_issue_discard(ibd->ibd_bd, lba, range,
GFP_KERNEL, 0);
if (ret < 0) {