Skip to contentSkip to conversation

scsi: Don't check uninitialized local variable

PATCH Applied Fam Zheng 4 participants 5 messages Jan 8, 2018 – Jan 9, 2018 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 scsi: Don't check uninitialized local variable

After the out label there is a check on iTask.task but it is not initialized yet.

Fixes e38bc23454ef763deb4405ebdee6a1081aa00bc8
---
 block/iscsi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/iscsi.c +1 -2
index 5c0a9e55b6..1cb8cc93c5 100644
@@ -659,8 +659,7 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,
     int64_t ret;
 
     if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
 
     /* default to all sectors allocated */
Signature · 1 line
2.14.3
#1 lore raw

Am 08.01.2018 um 04:09 schrieb Fam Zheng:

Quoted 14 lines

After the out label there is a check on iTask.task but it is not initialized yet.

Fixes e38bc23454ef763deb4405ebdee6a1081aa00bc8
---
  block/iscsi.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
block/iscsi.c +0 -0
index 5c0a9e55b6..1cb8cc93c5 100644

block/iscsi.c static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, · line 665

Quoted 9 lines
block/iscsi.c +1 -2
@@ -659,8 +659,7 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,
      int64_t ret;
 
      if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
      }
 
      /* default to all sectors allocated */

If lbpme is 0 we run into the same error. And this is even more likely than an unaligned request.

I think the right patch is to move the init of iTask up again where it was:

block/iscsi.c +0 -0
index 5c0a9e5..6a1c537 100644
@@ -658,6 +658,8 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,

     uint64_t lba;
     int64_t ret;

+    iscsi_co_init_iscsitask(iscsilun, &iTask);
+
     if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
         ret = -EINVAL;
         goto out;
@@ -675,7 +677,6 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,

     lba = sector_qemu2lun(sector_num, iscsilun);

-    iscsi_co_init_iscsitask(iscsilun, &iTask); qemu_mutex_lock(&iscsilun->mutex);
 retry:
     if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun,

Peter

Signature · 16 lines
Mit freundlichen Grüßen

Peter Lieven

...........................................................

  KAMP Netzwerkdienste GmbH
  Vestische Str. 89-91 | 46117 Oberhausen
  Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
  [email protected] | http://www.kamp.de

  Geschäftsführer: Heiner Lante | Michael Lante
  Amtsgericht Duisburg | HRB Nr. 12154
  USt-Id-Nr.: DE 120607556

...........................................................
Reviewed-by
#2 lore raw
Quoted 11 lines · Peter Lieven

Am 08.01.2018 um 04:09 schrieb Fam Zheng:

Quoted 9 lines

After the out label there is a check on iTask.task but it is not initialized yet.

Fixes e38bc23454ef763deb4405ebdee6a1081aa00bc8

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

  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 2 lines

If lbpme is 0 we run into the same error. And this is even more likely than an unaligned request.

In fact, my byte-based series adds an assertion that unaligned requests aren't possible.

Quoted 2 lines

I think the right patch is to move the init of iTask up again where it was:

I had to rebase v7 of my byte-based series on top of the late iTask initialization; moving it back to early initialization makes sense.

Quoted 24 lines
block/iscsi.c +2 -0
index 5c0a9e5..6a1c537 100644
@@ -658,6 +658,8 @@ static int64_t coroutine_fn
 iscsi_co_get_block_status(BlockDriverState *bs,
      uint64_t lba;
      int64_t ret;
 
+    iscsi_co_init_iscsitask(iscsilun, &iTask);
+
      if (!is_sector_request_lun_aligned(sector_num, nb_sectors,
 iscsilun)) {

         ret = -EINVAL;
         goto out;

block/iscsi.c +0 -1
@@ -675,7 +677,6 @@ static int64_t coroutine_fn
 iscsi_co_get_block_status(BlockDriverState *bs,
 
      lba = sector_qemu2lun(sector_num, iscsilun);
 
-    iscsi_co_init_iscsitask(iscsilun, &iTask);
      qemu_mutex_lock(&iscsilun->mutex);
Quoted 2 lines

 retry:
     if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun,

If you resubmit this as a formal patch, you can add:

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw
In reply to Fam Zheng
Quoted 15 lines · Fam Zheng

After the out label there is a check on iTask.task but it is not initialized yet.

Fixes e38bc23454ef763deb4405ebdee6a1081aa00bc8
---
 block/iscsi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/iscsi.c +0 -0
index 5c0a9e55b6..1cb8cc93c5 100644

block/iscsi.c static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, · line 665

Quoted 9 lines
block/iscsi.c +1 -2
@@ -659,8 +659,7 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,
     int64_t ret;
 
     if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
 
     /* default to all sectors allocated */

Queued, thanks.

Paolo

#4 lore raw
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Fam Zheng

After the out label there is a check on iTask.task but it is not initialized yet.

Fixes e38bc23454ef763deb4405ebdee6a1081aa00bc8
---
 block/iscsi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/iscsi.c +1 -2
index 5c0a9e55b6..1cb8cc93c5 100644
@@ -659,8 +659,7 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,
     int64_t ret;
 
     if (!is_sector_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
-        ret = -EINVAL;
-        goto out;
+        return -EINVAL;
     }
 
Quoted 4 lines

block/iscsi.c static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, · line 665

Quoted 2 lines
block/iscsi.c +0 -0
     /* default to all sectors allocated */

Queued, thanks.

I thought we wanted Peter's version, not Fam's.
https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg01237.html

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org