Skip to contentSkip to conversation

iscsi: Don't access non-existent scsi_lba_status_descriptor

PATCH In review Kevin Wolf 5 participants 7 messages Jan 23, 2020 – Jan 24, 2020 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 iscsi: Don't access non-existent scsi_lba_status_descriptor

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
 block/iscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +1 -1
index cbd57294ab..c8feaa2f0e 100644
@@ -753,7 +753,7 @@ retry:
     }
 
     lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
         ret = -EIO;
         goto out_unlock;
     }
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Kevin Wolf

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
block/iscsi.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +1 -1
index cbd57294ab..c8feaa2f0e 100644
@@ -753,7 +753,7 @@ retry:
    }
 
    lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
        ret = -EIO;
        goto out_unlock;
    }
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kevin Wolf
Quoted 15 lines · Kevin Wolf

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
 block/iscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +0 -0
index cbd57294ab..c8feaa2f0e 100644

block/iscsi.c retry: · line 759

Quoted 8 lines
block/iscsi.c +1 -1
@@ -753,7 +753,7 @@ retry:
     }
 
     lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
         ret = -EIO;
         goto out_unlock;
     }

Naive question: Does the specification allow for such a response? Is this inherently an error?

Anyway, this is better than accessing junk memory, so:

#3 lore raw
Quoted 23 lines · John Snow
Quoted 16 lines · Kevin Wolf

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
block/iscsi.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +0 -0
index cbd57294ab..c8feaa2f0e 100644
@@ -753,7 +753,7 @@ retry:
    }
 
Quoted 10 lines

block/iscsi.c retry: · line 759

Quoted 7 lines
block/iscsi.c +1 -1
    lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
        ret = -EIO;
        goto out_unlock;
    }

Naive question: Does the specification allow for such a response? Is this inherently an error?

The spec doesn't say, but libiscsi (which Qemu should trust) may return zero for num_descriptors with certain server responses (which no one should trust).

https://github.com/sahlberg/libiscsi/blob/master/lib/scsi-lowlevel.c#L845

F.

Quoted 4 lines

Anyway, this is better than accessing junk memory, so:

Reviewed-by
#4 lore raw
In reply to John Snow

Am 23.01.2020 um 21:38 schrieb John Snow <[email protected]>:

Quoted 20 lines



Quoted 17 lines · Kevin Wolf

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
block/iscsi.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +0 -0
index cbd57294ab..c8feaa2f0e 100644
@@ -753,7 +753,7 @@ retry:
    }
 
Quoted 10 lines

block/iscsi.c retry: · line 759

Quoted 7 lines
block/iscsi.c +1 -1
    lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
        ret = -EIO;
        goto out_unlock;
    }

Naive question: Does the specification allow for such a response? Is this inherently an error?

The spec says the answer SHALL contain at least one lbasd. So I think threating zero as an error is okay

Anyway,

Peter

author
#5 lore raw
In reply to John Snow

Am 23.01.2020 um 21:37 hat John Snow geschrieben:

Quoted 17 lines · Kevin Wolf
Quoted 16 lines

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
 block/iscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +0 -0
index cbd57294ab..c8feaa2f0e 100644
@@ -753,7 +753,7 @@ retry:
     }
 
Quoted 10 lines

block/iscsi.c retry: · line 759

Quoted 7 lines
block/iscsi.c +1 -1
     lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
         ret = -EIO;
         goto out_unlock;
     }

Naive question: Does the specification allow for such a response? Is this inherently an error?

Even if iscsi allowed it, it would be a useless response, because it means that you didn't get the block status of any block.

bdrv_co_block_status() may only return *pnum == 0 at EOF, so I don't think we have any other option than returning an error. (We could retry, but if a target returns a useless response once, why should we trust it do behave better the second time?)

Quoted 3 lines

Anyway, this is better than accessing junk memory, so:

Thanks!

Kevin

Reviewed-by on v1 1/1
#6 lore raw
In reply to Kevin Wolf
Quoted 15 lines · Kevin Wolf

In iscsi_co_block_status(), we may have received num_descriptors == 0 from the iscsi server. Therefore, we can't unconditionally access lbas->descriptors[0]. Add the missing check.

---
  block/iscsi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +0 -0
index cbd57294ab..c8feaa2f0e 100644

block/iscsi.c retry: · line 759

Quoted 8 lines
block/iscsi.c +1 -1
@@ -753,7 +753,7 @@ retry:
      }
 
      lbas = scsi_datain_unmarshall(iTask.task);
-    if (lbas == NULL) {
+    if (lbas == NULL || lbas->num_descriptors == 0) {
          ret = -EIO;
          goto out_unlock;
      }