From: Kevin Wolf <kwolf@redhat.com>
To: Zhang Haoyu <zhanghy@sangfor.com>
Cc: qemu-devel <qemu-devel@nongnu.org>, kvm <kvm@vger.kernel.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [PATCH] qcow2: fix double-free of Qcow2DiscardRegion in qcow2_process_discards
Date: Sun, 12 Oct 2014 09:34:32 +0200 [thread overview]
Message-ID: <20141012073432.GA3739@noname.redhat.com> (raw)
In-Reply-To: <201410111514227991260@sangfor.com>
Am 11.10.2014 um 09:14 hat Zhang Haoyu geschrieben:
> In qcow2_update_snapshot_refcount -> qcow2_process_discards() -> bdrv_discard()
> may free the Qcow2DiscardRegion which is referenced by "next" pointer in
> qcow2_process_discards() now, in next iteration, d = next, so g_free(d)
> will double-free this Qcow2DiscardRegion.
>
> qcow2_snapshot_delete
> |- qcow2_update_snapshot_refcount
> |-- qcow2_process_discards
> |--- bdrv_discard
> |---- aio_poll
> |----- aio_dispatch
> |------ bdrv_co_io_em_complete
> |------- qemu_coroutine_enter(co->coroutine, NULL); <=== coroutine entry is bdrv_co_do_rw
> |--- g_free(d) <== free first Qcow2DiscardRegion is okay
> |--- d = next; <== this set is done in QTAILQ_FOREACH_SAFE() macro.
> |--- g_free(d); <== double-free will happen if during previous iteration, bdrv_discard had free this object.
Do you have a reproducer for this or did code review lead you to this?
At the moment I can't see how bdrv_discard(bs->file) could ever free a
Qcow2DiscardRegion of bs, as it's working on a completely different
BlockDriverState (which usually won't even be a qcow2 one).
> bdrv_co_do_rw
> |- bdrv_co_do_writev
> |-- bdrv_co_do_pwritev
> |--- bdrv_aligned_pwritev
> |---- qcow2_co_writev
> |----- qcow2_alloc_cluster_link_l2
> |------ qcow2_free_any_clusters
> |------- qcow2_free_clusters
> |-------- update_refcount
> |--------- qcow2_process_discards
> |---------- g_free(d) <== In next iteration, this Qcow2DiscardRegion will be double-free.
This shouldn't happen in a nested call either, as s->lock can't be taken
recursively.
Kevin
WARNING: multiple messages have this Message-ID (diff)
From: Kevin Wolf <kwolf@redhat.com>
To: Zhang Haoyu <zhanghy@sangfor.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>, kvm <kvm@vger.kernel.org>
Subject: Re: [Qemu-devel] [PATCH] qcow2: fix double-free of Qcow2DiscardRegion in qcow2_process_discards
Date: Sun, 12 Oct 2014 09:34:32 +0200 [thread overview]
Message-ID: <20141012073432.GA3739@noname.redhat.com> (raw)
In-Reply-To: <201410111514227991260@sangfor.com>
Am 11.10.2014 um 09:14 hat Zhang Haoyu geschrieben:
> In qcow2_update_snapshot_refcount -> qcow2_process_discards() -> bdrv_discard()
> may free the Qcow2DiscardRegion which is referenced by "next" pointer in
> qcow2_process_discards() now, in next iteration, d = next, so g_free(d)
> will double-free this Qcow2DiscardRegion.
>
> qcow2_snapshot_delete
> |- qcow2_update_snapshot_refcount
> |-- qcow2_process_discards
> |--- bdrv_discard
> |---- aio_poll
> |----- aio_dispatch
> |------ bdrv_co_io_em_complete
> |------- qemu_coroutine_enter(co->coroutine, NULL); <=== coroutine entry is bdrv_co_do_rw
> |--- g_free(d) <== free first Qcow2DiscardRegion is okay
> |--- d = next; <== this set is done in QTAILQ_FOREACH_SAFE() macro.
> |--- g_free(d); <== double-free will happen if during previous iteration, bdrv_discard had free this object.
Do you have a reproducer for this or did code review lead you to this?
At the moment I can't see how bdrv_discard(bs->file) could ever free a
Qcow2DiscardRegion of bs, as it's working on a completely different
BlockDriverState (which usually won't even be a qcow2 one).
> bdrv_co_do_rw
> |- bdrv_co_do_writev
> |-- bdrv_co_do_pwritev
> |--- bdrv_aligned_pwritev
> |---- qcow2_co_writev
> |----- qcow2_alloc_cluster_link_l2
> |------ qcow2_free_any_clusters
> |------- qcow2_free_clusters
> |-------- update_refcount
> |--------- qcow2_process_discards
> |---------- g_free(d) <== In next iteration, this Qcow2DiscardRegion will be double-free.
This shouldn't happen in a nested call either, as s->lock can't be taken
recursively.
Kevin
next prev parent reply other threads:[~2014-10-12 7:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-11 7:14 [PATCH] qcow2: fix double-free of Qcow2DiscardRegion in qcow2_process_discards Zhang Haoyu
2014-10-11 7:14 ` [Qemu-devel] " Zhang Haoyu
2014-10-12 7:34 ` Kevin Wolf [this message]
2014-10-12 7:34 ` Kevin Wolf
2014-10-12 8:22 ` Zhang Haoyu
2014-10-12 8:22 ` Zhang Haoyu
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=20141012073432.GA3739@noname.redhat.com \
--to=kwolf@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=zhanghy@sangfor.com \
/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.