From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKty3-0005Vy-HG for qemu-devel@nongnu.org; Mon, 09 Feb 2015 14:26:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKty2-0003Sv-J0 for qemu-devel@nongnu.org; Mon, 09 Feb 2015 14:25:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51999) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKty2-0003Sj-Ar for qemu-devel@nongnu.org; Mon, 09 Feb 2015 14:25:58 -0500 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 t19JPv5E025337 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 9 Feb 2015 14:25:57 -0500 From: Max Reitz Date: Mon, 9 Feb 2015 14:25:43 -0500 Message-Id: <1423509950-7468-6-git-send-email-mreitz@redhat.com> In-Reply-To: <1423509950-7468-1-git-send-email-mreitz@redhat.com> References: <1423509950-7468-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 05/12] qcow2/overlaps: Protect refcount table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Keep track of the refcount table in the metadata list to protect it against accidental modifications. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/qcow2-refcount.c | 18 ++++++++++++++++++ block/qcow2.c | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 9b80ca7..ea08673 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -433,6 +433,14 @@ static int alloc_refcount_block(BlockDriverState *bs, s->refcount_table_size = table_size; s->refcount_table_offset = table_offset; + qcow2_metadata_list_remove(bs, old_table_offset, + size_to_clusters(s, old_table_size * + sizeof(uint64_t)), + QCOW2_OL_REFCOUNT_TABLE); + + qcow2_metadata_list_enter(bs, table_offset, table_clusters, + QCOW2_OL_REFCOUNT_TABLE); + /* Free old table. */ qcow2_free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t), QCOW2_DISCARD_OTHER); @@ -1948,6 +1956,16 @@ write_refblocks: goto fail; } + qcow2_metadata_list_remove(bs, s->refcount_table_offset, + size_to_clusters(s, s->refcount_table_size + * sizeof(uint64_t)), + QCOW2_OL_REFCOUNT_TABLE); + + qcow2_metadata_list_enter(bs, reftable_offset, + size_to_clusters(s, reftable_size * + sizeof(uint64_t)), + QCOW2_OL_REFCOUNT_TABLE); + for (refblock_index = 0; refblock_index < reftable_size; refblock_index++) { be64_to_cpus(&on_disk_reftable[refblock_index]); } diff --git a/block/qcow2.c b/block/qcow2.c index b61dab5..e9f4824 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -780,6 +780,10 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, error_setg(errp, "Invalid reference count table offset"); goto fail; } + qcow2_metadata_list_enter(bs, s->refcount_table_offset, + size_to_clusters(s, s->refcount_table_size * + sizeof(uint64_t)), + QCOW2_OL_REFCOUNT_TABLE); /* Snapshot table offset/length */ if (header.nb_snapshots > QCOW_MAX_SNAPSHOTS) { -- 2.1.0