Skip to contentSkip to conversation

check for bs->drv in bdrv_flush

PATCH Applied Christoph Hellwig 2 participants 3 messages Mar 28, 2009 – Mar 29, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check for bs->drv in bdrv_flush

All the bdrv_ helpers should check for bs->drv being zero as that means there is no backend image open. bdrv_flush fails to perform that check and can thus cause NULL pointer dereferences.

Found using qemu-io.

block.c +2 -0
Index: qemu/block.c
===================================================================
@@ -979,6 +979,8 @@ const char *bdrv_get_device_name(BlockDr
 
 void bdrv_flush(BlockDriverState *bs)
 {
+    if (!bs->drv)
+        return;
     if (bs->drv->bdrv_flush)
         bs->drv->bdrv_flush(bs);
     if (bs->backing_hd)
#1 lore raw
Quoted 6 lines · Christoph Hellwig

All the bdrv_ helpers should check for bs->drv being zero as that means there is no backend image open. bdrv_flush fails to perform that check and can thus cause NULL pointer dereferences.

Found using qemu-io.

Applied. Thanks.

FWIW, I plan to include qemu-io once you rebase the series to use IOVectors instead of struct iovec. It looks like a useful tool!

Regards,

Anthony Liguori

Quoted 20 lines

Index: qemu/block.c
===================================================================

block.c +2 -0
@@ -979,6 +979,8 @@ const char *bdrv_get_device_name(BlockDr
 
 void bdrv_flush(BlockDriverState *bs)
 {
+    if (!bs->drv)
+        return;
     if (bs->drv->bdrv_flush)
         bs->drv->bdrv_flush(bs);
     if (bs->backing_hd)
#2 lore raw
Quoted 5 lines · Anthony Liguori
Quoted 4 lines · Christoph Hellwig

All the bdrv_ helpers should check for bs->drv being zero as that means there is no backend image open. bdrv_flush fails to perform that check and can thus cause NULL pointer dereferences.

Quoted 7 lines
Quoted 2 lines

Found using qemu-io.

Applied. Thanks.

FWIW, I plan to include qemu-io once you rebase the series to use IOVectors instead of struct iovec. It looks like a useful tool!

The repost already uses QEMUIOVectors, I'll resend it with a formal description.