]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools, qcow: Fix copy-on-write image corruption
authorPekka Enberg <penberg@kernel.org>
Wed, 20 Jul 2011 13:28:31 +0000 (16:28 +0300)
committerPekka Enberg <penberg@kernel.org>
Wed, 20 Jul 2011 13:28:31 +0000 (16:28 +0300)
We don't handle refcount table properly so make sure we only write to clusters
that have the "copied" flag set.

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/disk/qcow.c

index bf0ac33a47aae5dc59a1396595ab42d18fc831a1..bffd4b63401ae4666e52d4f73327115a0240ed76 100644 (file)
@@ -429,7 +429,11 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src
 
        l2t_off = be64_to_cpu(table->l1_table[l1t_idx]);
        if (l2t_off & QCOW_OFLAG_COMPRESSED) {
-               pr_warning("compressed sectors are not supported");
+               pr_warning("compressed clusters are not supported");
+               goto error;
+       }
+       if (!(l2t_off & QCOW_OFLAG_COPIED)) {
+               pr_warning("copy-on-write clusters are not supported");
                goto error;
        }
 
@@ -472,7 +476,11 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src
 
        clust_start     = be64_to_cpu(l2t->table[l2t_idx]);
        if (clust_start & QCOW_OFLAG_COMPRESSED) {
-               pr_warning("compressed sectors are not supported");
+               pr_warning("compressed clusters are not supported");
+               goto error;
+       }
+       if (!(clust_start & QCOW_OFLAG_COPIED)) {
+               pr_warning("copy-on-write clusters are not supported");
                goto error;
        }