Skip to contentSkip to conversation

Block patches 2018-03-01

GIT PULL Applied Fam Zheng 2 participants 5 messages Mar 1, 2018 – May 21, 2018 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

The following changes since commit 6697439794f72b3501ee16bb95d16854f9981421:

Merge remote-tracking branch 'remotes/kraxel/tags/usb-20180227-pull-request' into staging (2018-02-27 17:50:46 +0000)

are available in the Git repository at:

git://github.com/famz/qemu.git tags/staging-pull-request

for you to fetch changes up to 78d8c99e297eba32897d8a5bdaa005670549d6f7:

block/nvme: fix Coverity reports (2018-03-01 15:21:46 +0800)

----------------------------------------------------------------

Coverity error fix for nvme://

----------------------------------------------------------------

Paolo Bonzini (1):
block/nvme: fix Coverity reports

 block/nvme.c        | 10 +++++++---
 util/vfio-helpers.c |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.3
author
#1 lore raw

[Qemu-devel] [PULL 1/1] block/nvme: fix Coverity reports

From: Paolo Bonzini <[email protected]>

1) string not null terminated in sysfs_find_group_file

2) NULL pointer dereference and dead local variable in nvme_init.

Message-Id: <[email protected]>

---
 block/nvme.c        | 10 +++++++---
 util/vfio-helpers.c |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
block/nvme.c +7 -3
index 10bffbbf2f..75078022f6 100644
@@ -645,7 +645,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
     aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier,
                            false, nvme_handle_event, nvme_poll_cb);
 
-    nvme_identify(bs, namespace, errp);
+    nvme_identify(bs, namespace, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EIO;
@@ -666,8 +666,12 @@ fail_queue:
     nvme_free_queue_pair(bs, s->queues[0]);
 fail:
     g_free(s->queues);
-    qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
-    qemu_vfio_close(s->vfio);
+    if (s->regs) {
+        qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
+    }
+    if (s->vfio) {
+        qemu_vfio_close(s->vfio);
+    }
     event_notifier_cleanup(&s->irq_notifier);
     return ret;
 }
util/vfio-helpers.c +1 -1
index f478b68400..006674c916 100644
@@ -104,7 +104,7 @@ static char *sysfs_find_group_file(const char *device, Error **errp)
     char *path = NULL;
 
     sysfs_link = g_strdup_printf("/sys/bus/pci/devices/%s/iommu_group", device);
-    sysfs_group = g_malloc(PATH_MAX);
+    sysfs_group = g_malloc0(PATH_MAX);
     if (readlink(sysfs_link, sysfs_group, PATH_MAX - 1) == -1) {
         error_setg_errno(errp, errno, "Failed to find iommu group sysfs path");
         goto out;
Signature · 1 line
2.14.3
#4 lore raw
In reply to Fam Zheng
Quoted 18 lines · Fam Zheng

The following changes since commit 6697439794f72b3501ee16bb95d16854f9981421:

Merge remote-tracking branch 'remotes/kraxel/tags/usb-20180227-pull-request' into staging (2018-02-27 17:50:46 +0000)

are available in the Git repository at:

git://github.com/famz/qemu.git tags/staging-pull-request

for you to fetch changes up to 78d8c99e297eba32897d8a5bdaa005670549d6f7:

block/nvme: fix Coverity reports (2018-03-01 15:21:46 +0800)

----------------------------------------------------------------

Coverity error fix for nvme://

----------------------------------------------------------------

Quoted 8 lines

Paolo Bonzini (1):
block/nvme: fix Coverity reports

 block/nvme.c        | 10 +++++++---
 util/vfio-helpers.c |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

--

Applied, thanks.

-- PMM

#2 lore raw

Re: [Qemu-devel] [PULL 1/1] block/nvme: fix Coverity reports

In reply to Fam Zheng
Quoted 11 lines · Fam Zheng

From: Paolo Bonzini <[email protected]>

1) string not null terminated in sysfs_find_group_file

2) NULL pointer dereference and dead local variable in nvme_init.

Message-Id: <[email protected]>

Hi. It looks like Coverity still doesn't like the error-exit handling in nvme_init() (CID 1385847):

Quoted 19 lines
---
 block/nvme.c        | 10 +++++++---
 util/vfio-helpers.c |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
block/nvme.c +1 -1
index 10bffbbf2f..75078022f6 100644
@@ -645,7 +645,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
     aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier,
                            false, nvme_handle_event, nvme_poll_cb);
 
-    nvme_identify(bs, namespace, errp);
+    nvme_identify(bs, namespace, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EIO;

block/nvme.c fail_queue: · line 670

Quoted 7 lines
block/nvme.c +2 -2
@@ -666,8 +666,12 @@ fail_queue:
     nvme_free_queue_pair(bs, s->queues[0]);
 fail:
     g_free(s->queues);
-    qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
-    qemu_vfio_close(s->vfio);
+    if (s->regs) {
+        qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);

We can get here with s->vfio being NULL and s->regs being uninitialized, but qemu_vfio_pci_unmap_bar() will unconditionally dereference s->vfio.

If you want to write the error path like this I think you need to initialize s->regs = NULL before we do the qemu_vfio_open_pci() call and error-check.

block/nvme.c fail_queue: · line 677

Quoted 7 lines
block/nvme.c +4 -0
+    }
+    if (s->vfio) {
+        qemu_vfio_close(s->vfio);
+    }
     event_notifier_cleanup(&s->irq_notifier);
     return ret;
 }

thanks
-- PMM

author
#3 lore raw

Re: [Qemu-devel] [PULL 1/1] block/nvme: fix Coverity reports

Quoted 47 lines · Peter Maydell
Quoted 11 lines · Fam Zheng

From: Paolo Bonzini <[email protected]>

1) string not null terminated in sysfs_find_group_file

2) NULL pointer dereference and dead local variable in nvme_init.

Message-Id: <[email protected]>

Hi. It looks like Coverity still doesn't like the error-exit handling in nvme_init() (CID 1385847):

Quoted 19 lines
---
 block/nvme.c        | 10 +++++++---
 util/vfio-helpers.c |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)
block/nvme.c +1 -1
index 10bffbbf2f..75078022f6 100644
@@ -645,7 +645,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
     aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier,
                            false, nvme_handle_event, nvme_poll_cb);
 
-    nvme_identify(bs, namespace, errp);
+    nvme_identify(bs, namespace, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EIO;

block/nvme.c fail_queue: · line 670

Quoted 7 lines
block/nvme.c +2 -2
@@ -666,8 +666,12 @@ fail_queue:
     nvme_free_queue_pair(bs, s->queues[0]);
 fail:
     g_free(s->queues);
-    qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
-    qemu_vfio_close(s->vfio);
+    if (s->regs) {
+        qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);

We can get here with s->vfio being NULL and s->regs being uninitialized, but qemu_vfio_pci_unmap_bar() will unconditionally dereference s->vfio.

Quoted 3 lines

If you want to write the error path like this I think you need to initialize s->regs = NULL before we do the qemu_vfio_open_pci() call and error-check.

Block layer uses g_malloc0 to allocate *s, so we expect s->regs is NULL to begin with. But I can send a patch to explicitly initialize it to NULL to make the code simpler to reason.

Fam

Quoted 11 lines

block/nvme.c fail_queue: · line 677

Quoted 8 lines
block/nvme.c +4 -0
+    }
+    if (s->vfio) {
+        qemu_vfio_close(s->vfio);
+    }
     event_notifier_cleanup(&s->irq_notifier);
     return ret;
 }

thanks
-- PMM