All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: gerben@altlinux.org
Cc: qemu-devel@nongnu.org, hreitz@redhat.com, sdl.qemu@linuxtesting.org
Subject: Re: [PATCH] block/vmdk: prevent double-free in extent memory management
Date: Mon, 10 Mar 2025 11:35:43 +0100	[thread overview]
Message-ID: <Z87Afzk_3r6ft_J4@redhat.com> (raw)
In-Reply-To: <20250304090415.39393-1-gerben@altlinux.org>

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



      reply	other threads:[~2025-03-10 10:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04  9:04 [PATCH] block/vmdk: prevent double-free in extent memory management gerben
2025-03-10 10:35 ` Kevin Wolf [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z87Afzk_3r6ft_J4@redhat.com \
    --to=kwolf@redhat.com \
    --cc=gerben@altlinux.org \
    --cc=hreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sdl.qemu@linuxtesting.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.