Skip to contentSkip to conversation

block/vmdk: prevent double-free in extent memory management

PATCH In review [email protected] 2 participants 2 messages Mar 4, 2025 – Mar 10, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/vmdk: prevent double-free in extent memory management

From: Denis Rastyogin <[email protected]>

This error was discovered by fuzzing qemu-img.

A double-free issue in the VMDK driver occurs when handling snapshots. The memory allocated for extent structures is freed twice: first in vmdk_close (block/vmdk.c) and then in vmdk_add_extent (block/vmdk.c).

The fix ensures the s->extents pointer is set to NULL after freeing, preventing double-free.

---
 block/vmdk.c | 1 +
 1 file changed, 1 insertion(+)
block/vmdk.c +1 -0
index 2adec49912..d6baa54602 100644
@@ -285,6 +285,7 @@ static void vmdk_free_extents(BlockDriverState *bs)
     bdrv_graph_wrunlock();
 
     g_free(s->extents);
+    s->extents = NULL;
 }
 
 static void vmdk_free_last_extent(BlockDriverState *bs)
Signature · 1 line
2.42.2
#1 lore raw

Am 04.03.2025 um 10:04 hat [email protected] geschrieben:

Quoted 22 lines

From: Denis Rastyogin <[email protected]>

This error was discovered by fuzzing qemu-img.

A double-free issue in the VMDK driver occurs when handling snapshots. The memory allocated for extent structures is freed twice: first in vmdk_close (block/vmdk.c) and then in vmdk_add_extent (block/vmdk.c).

The fix ensures the s->extents pointer is set to NULL after freeing, preventing double-free.

---
 block/vmdk.c | 1 +
 1 file changed, 1 insertion(+)
block/vmdk.c +0 -0
index 2adec49912..d6baa54602 100644

block/vmdk.c static void vmdk_free_extents(BlockDriverState *bs) · line 289

Quoted 5 lines
block/vmdk.c +1 -0
@@ -285,6 +285,7 @@ static void vmdk_free_extents(BlockDriverState *bs)
     bdrv_graph_wrunlock();
 
     g_free(s->extents);
+    s->extents = NULL;
 }

This is not the right fix. It only papers over the real bug, which is that bdrv_snapshot_goto() calls .bdrv_open() for a BlockDriverState whose bs->opaque hasn't been zeroed. Open functions of block drivers generally rely on having a zeroed state.

Kevin