]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commit
qcow2: Don't rely on free_cluster_index in alloc_refcount_block() (CVE-2014-0147)
authorKevin Wolf <kwolf@redhat.com>
Fri, 28 Mar 2014 17:06:31 +0000 (18:06 +0100)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Thu, 3 Jul 2014 21:18:12 +0000 (16:18 -0500)
commitffa3ab02174f7cb474366bc325bd35264364c9fd
tree3751a1f3c40dc7b8f85537f371dceec5d87e2732
parentaeba41549da75d5775165e9205170e5b7a30f016
qcow2: Don't rely on free_cluster_index in alloc_refcount_block() (CVE-2014-0147)

free_cluster_index is only correct if update_refcount() was called from
an allocation function, and even there it's brittle because it's used to
protect unfinished allocations which still have a refcount of 0 - if it
moves in the wrong place, the unfinished allocation can be corrupted.

So not using it any more seems to be a good idea. Instead, use the
first requested cluster to do the calculations. Return -EAGAIN if
unfinished allocations could become invalid and let the caller restart
its search for some free clusters.

The context of creating a snapsnot is one situation where
update_refcount() is called outside of a cluster allocation. For this
case, the change fixes a buffer overflow if a cluster is referenced in
an L2 table that cannot be represented by an existing refcount block.
(new_table[refcount_table_index] was out of bounds)

[Bump the qemu-iotests 026 refblock_alloc.write leak count from 10 to
11.
--Stefan]

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit b106ad9185f35fc4ad669555ad0e79e276083bd7)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
block/qcow2-refcount.c
block/qcow2.c
tests/qemu-iotests/026.out
tests/qemu-iotests/044.out
tests/qemu-iotests/080
tests/qemu-iotests/080.out