qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PULL 14/16] block/qcow2: Fix corruption introduced by commit 8ac0f15f335
Date: Mon, 16 Sep 2019 16:22:44 +0200	[thread overview]
Message-ID: <20190916142246.31474-15-mreitz@redhat.com> (raw)
In-Reply-To: <20190916142246.31474-1-mreitz@redhat.com>

From: Maxim Levitsky <mlevitsk@redhat.com>

This fixes subtle corruption introduced by luks threaded encryption
in commit 8ac0f15f335

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1745922

The corruption happens when we do a write that
   * writes to two or more unallocated clusters at once
   * doesn't fully cover the first sector
   * doesn't fully cover the last sector
   * uses luks encryption

In this case, when allocating the new clusters we COW both areas
prior to the write and after the write, and we encrypt them.

The above mentioned commit accidentally made it so we encrypt the
second COW area using the physical cluster offset of the first area.

The problem is that offset_in_cluster in do_perform_cow_encrypt
can be larger that the cluster size, thus cluster_offset
will no longer point to the start of the cluster at which encrypted
area starts.

Next patch in this series will refactor the code to avoid all these
assumptions.

In the bugreport that was triggered by rebasing a luks image to new,
zero filled base, which lot of such writes, and causes some files
with zero areas to contain garbage there instead.
But as described above it can happen elsewhere as well

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190915203655.21638-2-mlevitsk@redhat.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/qcow2-cluster.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index cb44b6c6ba..cac0b6c7ba 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -474,9 +474,10 @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
         assert(QEMU_IS_ALIGNED(offset_in_cluster, BDRV_SECTOR_SIZE));
         assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE));
         assert(s->crypto);
-        if (qcow2_co_encrypt(bs, cluster_offset,
-                             src_cluster_offset + offset_in_cluster,
-                             buffer, bytes) < 0) {
+        if (qcow2_co_encrypt(bs,
+                start_of_cluster(s, cluster_offset + offset_in_cluster),
+                src_cluster_offset + offset_in_cluster,
+                buffer, bytes) < 0) {
             return false;
         }
     }
-- 
2.21.0



  parent reply	other threads:[~2019-09-16 15:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16 14:22 [Qemu-devel] [PULL 00/16] Block patches Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 01/16] block: Use QEMU_IS_ALIGNED Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 02/16] block: Remove unused masks Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 03/16] tests/qemu-iotests/check: Replace "tests" with "iotests" in final status text Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 04/16] tests/Makefile: Do not print the name of the check-block.sh shell script Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 05/16] tests/qemu-iotests: Fix qemu-io related output in 026.out.nocache Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 06/16] curl: Keep pointer to the CURLState in CURLSocket Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 07/16] curl: Keep *socket until the end of curl_sock_cb() Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 08/16] curl: Check completion in curl_multi_do() Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 09/16] curl: Pass CURLSocket to curl_multi_do() Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 10/16] curl: Report only ready sockets Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 11/16] curl: Handle success in multi_check_completion Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 12/16] curl: Check curl_multi_add_handle()'s return code Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 13/16] blockjob: update nodes head while removing all bdrv Max Reitz
2019-09-16 14:22 ` Max Reitz [this message]
2019-09-16 14:22 ` [Qemu-devel] [PULL 15/16] block/qcow2: refactor encryption code Max Reitz
2019-09-16 14:22 ` [Qemu-devel] [PULL 16/16] qemu-iotests: Add test for bz #1745922 Max Reitz
2019-09-16 15:34 ` [Qemu-devel] [PULL 00/16] Block patches no-reply
2019-09-17  9:20 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190916142246.31474-15-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).