* [PATCH] block/vmdk: prevent double-free in extent memory management
@ 2025-03-04 9:04 gerben
2025-03-10 10:35 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: gerben @ 2025-03-04 9:04 UTC (permalink / raw)
To: qemu-devel, kwolf, hreitz; +Cc: sdl.qemu
From: Denis Rastyogin <gerben@altlinux.org>
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.
Closes: https://gitlab.com/qemu-project/qemu/-/issues/2853
Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
---
block/vmdk.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block/vmdk.c b/block/vmdk.c
index 2adec49912..d6baa54602 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -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)
--
2.42.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] block/vmdk: prevent double-free in extent memory management
2025-03-04 9:04 [PATCH] block/vmdk: prevent double-free in extent memory management gerben
@ 2025-03-10 10:35 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2025-03-10 10:35 UTC (permalink / raw)
To: gerben; +Cc: qemu-devel, hreitz, sdl.qemu
Am 04.03.2025 um 10:04 hat gerben@altlinux.org geschrieben:
> From: Denis Rastyogin <gerben@altlinux.org>
>
> 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.
>
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/2853
> Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
> ---
> block/vmdk.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 2adec49912..d6baa54602 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-10 10:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04 9:04 [PATCH] block/vmdk: prevent double-free in extent memory management gerben
2025-03-10 10:35 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).