diff mbox

block/iscsi: validate block size returned from target

Message ID 1439552016-8557-1-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven Aug. 14, 2015, 11:33 a.m. UTC
It has been reported that at least tgtd returns a block size of 0
for LUN 0. To avoid running into divide by zero later on and protect
against other problematic block sizes validate the block size right
at connection time.

Cc: qemu-stable@nongnu.org
Reported-by: Andrey Korolyov <andrey@xdel.ru>
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c | 4 ++++
 dtc           | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Peter Lieven Aug. 31, 2015, 8:38 a.m. UTC | #1
Am 14.08.2015 um 13:33 schrieb Peter Lieven:
> It has been reported that at least tgtd returns a block size of 0
> for LUN 0. To avoid running into divide by zero later on and protect
> against other problematic block sizes validate the block size right
> at connection time.
>
> Cc: qemu-stable@nongnu.org
> Reported-by: Andrey Korolyov <andrey@xdel.ru>
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>   block/iscsi.c | 4 ++++
>   dtc           | 2 +-
>   2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 5002916..fac3a7a 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -1214,6 +1214,10 @@ static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp)
>   
>       if (task == NULL || task->status != SCSI_STATUS_GOOD) {
>           error_setg(errp, "iSCSI: failed to send readcapacity10 command.");
> +    } else if (!iscsilun->block_size ||
> +               iscsilun->block_size % BDRV_SECTOR_SIZE) {
> +        error_setg(errp, "iSCSI: the target returned an invalid "
> +                   "block size of %d.", iscsilun->block_size);
>       }
>       if (task) {
>           scsi_free_scsi_task(task);

Ping
Paolo Bonzini Sept. 7, 2015, 10:39 a.m. UTC | #2
On 31/08/2015 10:38, Peter Lieven wrote:
>>
>> diff --git a/block/iscsi.c b/block/iscsi.c
>> index 5002916..fac3a7a 100644
>> --- a/block/iscsi.c
>> +++ b/block/iscsi.c
>> @@ -1214,6 +1214,10 @@ static void iscsi_readcapacity_sync(IscsiLun
>> *iscsilun, Error **errp)
>>         if (task == NULL || task->status != SCSI_STATUS_GOOD) {
>>           error_setg(errp, "iSCSI: failed to send readcapacity10
>> command.");
>> +    } else if (!iscsilun->block_size ||
>> +               iscsilun->block_size % BDRV_SECTOR_SIZE) {
>> +        error_setg(errp, "iSCSI: the target returned an invalid "
>> +                   "block size of %d.", iscsilun->block_size);
>>       }
>>       if (task) {
>>           scsi_free_scsi_task(task);
> 
> Ping

Queued but not sent due to KVM Forum and vacation.

Paolo
diff mbox

Patch

diff --git a/block/iscsi.c b/block/iscsi.c
index 5002916..fac3a7a 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1214,6 +1214,10 @@  static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp)
 
     if (task == NULL || task->status != SCSI_STATUS_GOOD) {
         error_setg(errp, "iSCSI: failed to send readcapacity10 command.");
+    } else if (!iscsilun->block_size ||
+               iscsilun->block_size % BDRV_SECTOR_SIZE) {
+        error_setg(errp, "iSCSI: the target returned an invalid "
+                   "block size of %d.", iscsilun->block_size);
     }
     if (task) {
         scsi_free_scsi_task(task);