Skip to contentSkip to conversation

blkverify: Fix BDS leak in .bdrv_open error path

PATCH In review Kevin Wolf 3 participants 6 messages Oct 13, 2015 – Oct 26, 2015 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

cover blkverify: Fix BDS leak in .bdrv_open error path

Kevin Wolf (2):
block: Allow bdrv_unref_child(bs, NULL)
blkverify: Fix BDS leak in .bdrv_open error path

 block.c           | 7 ++++++-
 block/blkverify.c | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 block: Allow bdrv_unref_child(bs, NULL)

bdrv_unref() can be called with a NULL argument and doesn't do anything then. Make bdrv_unref_child() consistent with it.

---
 block.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block.c +6 -1
index f38146e..6490040 100644
@@ -1104,12 +1104,17 @@ static void bdrv_detach_child(BdrvChild *child)
 
 void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child)
 {
-    BlockDriverState *child_bs = child->bs;
+    BlockDriverState *child_bs;
+
+    if (child == NULL) {
+        return;
+    }
 
     if (child->bs->inherits_from == parent) {
         child->bs->inherits_from = NULL;
     }
 
+    child_bs = child->bs;
     bdrv_detach_child(child);
     bdrv_unref(child_bs);
 }
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: Allow bdrv_unref_child(bs, NULL)

Quoted 34 lines · Kevin Wolf

bdrv_unref() can be called with a NULL argument and doesn't do anything then. Make bdrv_unref_child() consistent with it.

---
 block.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block.c +6 -1
index f38146e..6490040 100644
@@ -1104,12 +1104,17 @@ static void bdrv_detach_child(BdrvChild *child)
 
 void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child)
 {
-    BlockDriverState *child_bs = child->bs;
+    BlockDriverState *child_bs;
+
+    if (child == NULL) {
+        return;
+    }
 
     if (child->bs->inherits_from == parent) {
         child->bs->inherits_from = NULL;
     }
 
+    child_bs = child->bs;
     bdrv_detach_child(child);
     bdrv_unref(child_bs);
 }
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH 2/2 blkverify: Fix BDS leak in .bdrv_open error path

In reply to Kevin Wolf
---
 block/blkverify.c | 3 +++
 1 file changed, 3 insertions(+)
block/blkverify.c +3 -0
index f8655ad..c5f8e8d 100644
@@ -143,6 +143,9 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
 
     ret = 0;
 fail:
+    if (ret < 0) {
+        bdrv_unref_child(bs, bs->file);
+    }
     qemu_opts_del(opts);
     return ret;
 }
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/2
#4 lore raw
Quoted 22 lines · Kevin Wolf
---
 block/blkverify.c | 3 +++
 1 file changed, 3 insertions(+)
block/blkverify.c +3 -0
index f8655ad..c5f8e8d 100644
@@ -143,6 +143,9 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
 
     ret = 0;
 fail:
+    if (ret < 0) {
+        bdrv_unref_child(bs, bs->file);
+    }
     qemu_opts_del(opts);
     return ret;
 }
Signature · 1 line
1.8.3.1
Reviewed-by on the v1 series
#5 lore raw
In reply to Kevin Wolf
Quoted 4 lines · Kevin Wolf

Kevin Wolf (2):
block: Allow bdrv_unref_child(bs, NULL)
blkverify: Fix BDS leak in .bdrv_open error path

Quoted 8 lines
 block.c           | 7 ++++++-
 block/blkverify.c | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1