Kevin Wolf b106ad9185 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>
2014-04-01 15:21:03 +02:00
..
2013-10-28 17:34:42 +01:00
2012-03-12 15:14:07 +01:00
2014-02-14 16:22:33 +01:00
2014-02-14 16:22:33 +01:00
2014-02-14 21:07:13 +01:00
2014-02-14 20:50:19 +01:00
2014-02-14 16:22:33 +01:00
2014-03-13 01:21:45 +01:00
2014-02-14 16:22:33 +01:00
2013-02-01 08:32:20 +01:00
2014-02-14 21:02:27 +01:00
2014-03-13 01:21:56 +01:00
2014-02-14 21:01:03 +01:00
2014-03-13 01:21:56 +01:00
2014-02-14 16:22:33 +01:00