From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTfcq-0007cA-6s for qemu-devel@nongnu.org; Fri, 28 Mar 2014 18:51:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTfcj-0003ud-Lr for qemu-devel@nongnu.org; Fri, 28 Mar 2014 18:51:48 -0400 Message-ID: <5335FCF8.6070605@redhat.com> Date: Fri, 28 Mar 2014 23:51:36 +0100 From: Max Reitz MIME-Version: 1.0 References: <1395835569-21193-27-git-send-email-stefanha@redhat.com> <1396026391-31322-1-git-send-email-stefanha@redhat.com> In-Reply-To: <1396026391-31322-1-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 for-2.0 26/47] qcow2: Don't rely on free_cluster_index in alloc_refcount_block() (CVE-2014-0147) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , pmatouse@redhat.com, qemu-stable@nongnu.org On 28.03.2014 18:06, Stefan Hajnoczi wrote: > From: Kevin Wolf > > 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) > > Signed-off-by: Kevin Wolf > --- > v2: > * Fill new refcount block with zeroes when creating image. > > In v1 a dangling refcount table entry was created. When a qcow2 image is > created on a block device containing previous data (non-zero), the > dangling refcount table entry would be read! > > Failure scenario: > $ qemu-img create -f qcow2 /dev/loop0 30G > $ qemu-img create -f qcow2 /dev/loop0 30G > Huh, first cluster in empty image is already in use? > > block/qcow2-refcount.c | 72 ++++++++++++++++++++++++---------------------- > block/qcow2.c | 11 +++---- > tests/qemu-iotests/044.out | 2 +- > tests/qemu-iotests/080 | 11 +++++++ > tests/qemu-iotests/080.out | 7 +++++ > 5 files changed, 62 insertions(+), 41 deletions(-) Reviewed-by: Max Reitz