From patchwork Fri Oct 26 19:42:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 194559 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 867E72C0095 for ; Sat, 27 Oct 2012 06:42:45 +1100 (EST) Received: from localhost ([::1]:36948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRpnn-0003eM-Nw for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2012 15:42:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRpnJ-0002bs-LC for qemu-devel@nongnu.org; Fri, 26 Oct 2012 15:42:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRpnI-0004Z5-PL for qemu-devel@nongnu.org; Fri, 26 Oct 2012 15:42:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRpnI-0004Yv-HS for qemu-devel@nongnu.org; Fri, 26 Oct 2012 15:42:12 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9QJgBmO026856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Oct 2012 15:42:12 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-7-241.ams2.redhat.com [10.36.7.241]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9QJg9Mx019574; Fri, 26 Oct 2012 15:42:11 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2012 21:42:07 +0200 Message-Id: <1351280528-21889-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1351280528-21889-1-git-send-email-kwolf@redhat.com> References: <1351280528-21889-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH 1/2] qcow2: Fix refcount table size calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A missing factor for the refcount table entry size in the calculation could mean that too little memory was allocated for the in-memory representation of the table, resulting in a buffer overflow. Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 5e3f915..96224d1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -301,7 +301,8 @@ static int alloc_refcount_block(BlockDriverState *bs, uint64_t last_table_size; uint64_t blocks_clusters; do { - uint64_t table_clusters = size_to_clusters(s, table_size); + uint64_t table_clusters = + size_to_clusters(s, table_size * sizeof(uint64_t)); blocks_clusters = 1 + ((table_clusters + refcount_block_clusters - 1) / refcount_block_clusters);