]> git.proxmox.com Git - mirror_qemu.git/commit
block/mirror: Fix use-after-free
authorMax Reitz <mreitz@redhat.com>
Mon, 3 Apr 2017 17:51:49 +0000 (19:51 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 7 Apr 2017 12:44:05 +0000 (14:44 +0200)
commit7a25fcd056ddd34ee7abc906c957d252e2889461
treefe920473168525c8bcb464025ddb665dfbe83189
parent0d0676a1040d34339731a4e26a9b39b78c8a1fdf
block/mirror: Fix use-after-free

If @bs does not have any parents, the only reference to @mirror_top_bs
will be held by the BlockJob object after the bdrv_unref() following
block_job_create(). However, if block_job_create() fails, this reference
will not exist and @mirror_top_bs will have been deleted when we
goto fail.

The issue comes back at all later entries to the fail label: We delete
the BlockJob object before rolling back our changes to the node graph.
This means that we will delete @mirror_top_bs in the process.

All in all, whenever @bs does not have any parents and we go down the
fail path we will dereference @mirror_top_bs after it has been deleted.

Fix this by invoking bdrv_unref() only when block_job_create() was
successful and by bdrv_ref()'ing @mirror_top_bs in the fail path before
deleting the BlockJob object. Finally, bdrv_unref() it at the end of the
fail path after we actually no longer need it.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/mirror.c