]> xenbits.xensource.com Git - qemu-upstream-4.3-testing.git/commit
qcow2: Don't rely on free_cluster_index in alloc_refcount_block() (CVE-2014-0147)
authorKevin Wolf <kwolf@redhat.com>
Thu, 5 Mar 2015 10:52:50 +0000 (10:52 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Thu, 5 Mar 2015 17:12:13 +0000 (17:12 +0000)
commit982dc223ed348860a96a960a2920792a2815208e
treedecc4d7e140f139728c7884a67f07a3b24bc2e06
parent8c58457e2e407d3b674bbf0df61f75f6fcad4aee
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>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
block/qcow2-refcount.c
block/qcow2.c