From: Maxim Levitsky <mlevitsk@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
qemu-block@nongnu.org, qemu-stable <qemu-stable@nongnu.org>,
"Max Reitz" <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/3] block/qcow2: fix the corruption when rebasing luks encrypted files
Date: Fri, 06 Sep 2019 22:46:06 +0300 [thread overview]
Message-ID: <df8809e370526d5c0eb7987268c185b147855d07.camel@redhat.com> (raw)
In-Reply-To: <3ac8c65d-4bca-372c-d863-1f794292f5cb@redhat.com>
On Fri, 2019-09-06 at 14:17 -0500, Eric Blake wrote:
> On 9/6/19 12:32 PM, Maxim Levitsky wrote:
> > This fixes subltle corruption introduced by luks threaded encryption
>
> subtle
I usually put the commit messages to a spellchecker, but this time
I forgot to do this. I will try not to in the future.
>
> > in commit 8ac0f15f335
> >
> > Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1745922
> >
> > The corruption happens when we do
> > * write to two or more unallocated clusters at once
> > * write doesn't fully cover nether first nor last cluster
>
> s/nether/neither/
>
> or even:
>
> write doesn't fully cover either the first or the last cluster
I think I didn't wrote the double negative correctly here.
I meant a write that doesn't cover first sector fully and doesn't cover second sector.
I'll just write it like that I guess.
>
> >
> > In this case, when allocating the new clusters we COW both area
>
> areas
>
> > prior to the write and after the write, and we encrypt them.
> >
> > The above mentioned commit accidently made it so, we encrypt the
>
> accidentally
>
> s/made it so, we encrypt/changed the encryption of/
>
> > second COW are using the physical cluster offset of the first area.
>
> s/are using/to use/
I actually meant to write 'area' here. I just haven't proofed the commit
message at all I confess. Next time I do better.
>
> >
> > Fix this by:
> > * remove the offset_in_cluster parameter of do_perform_cow_encrypt
> > since it is misleading. That offset can be larger that cluster size.
> > instead just add the start and end COW are offsets to both host and guest offsets
> > that do_perform_cow_encrypt receives.
> >
> > * in do_perform_cow_encrypt, remove the cluster offset from the host_offset
> > And thus pass correctly to the qcow2_co_encrypt, the host cluster offset and full guest offset
> >
> >
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> > ---
> > block/qcow2-cluster.c | 26 +++++++++++++++-----------
> > 1 file changed, 15 insertions(+), 11 deletions(-)
> >
> > +++ b/block/qcow2-cluster.c
> > @@ -463,20 +463,20 @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,
> > }
> >
> > static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
> > - uint64_t guest_cluster_offset,
> > - uint64_t host_cluster_offset,
> > - unsigned offset_in_cluster,
> > + uint64_t guest_offset,
> > + uint64_t host_offset,
> > uint8_t *buffer,
> > unsigned bytes)
> > {
> > if (bytes && bs->encrypted) {
> > BDRVQcow2State *s = bs->opaque;
> > - assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0);
> > + assert((guest_offset & ~BDRV_SECTOR_MASK) == 0);
> > + assert((host_offset & ~BDRV_SECTOR_MASK) == 0);
> > assert((bytes & ~BDRV_SECTOR_MASK) == 0);
>
> Pre-existing, but we could use QEMU_IS_ALIGNED(x, BDRV_SECTOR_SIZE) for
> slightly more legibility than open-coding the bit operation.
>
> Neat trick about power-of-2 alignment checks:
>
> assert(QEMU_IS_ALIGNED(offset_in_cluster | guest_offset |
> host_offset | bytes, BDRV_SECTOR_SIZE));
In my book, a shorter code is almost always better, so why not.
>
> gives the same result in one assertion. (I've used it elsewhere in the
> code base, but I'm not opposed to one assert per variable if you think
> batching is too dense.)
>
> I'll let Dan review the actual code change, but offhand it makes sense
> to me.
>
Best regards,
Thanks for the review,
Maxim Levitsky
next prev parent reply other threads:[~2019-09-06 19:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 17:31 [Qemu-devel] [PATCH 0/3] Fix qcow2+luks corruption introduced by commit 8ac0f15f335 Maxim Levitsky
2019-09-06 17:31 ` [Qemu-devel] [PATCH 1/3] block/qcow2: refactoring of threaded encryption code Maxim Levitsky
2019-09-06 18:00 ` Eric Blake
2019-09-06 18:55 ` Maxim Levitsky
2019-09-06 19:00 ` Eric Blake
2019-09-06 19:03 ` Maxim Levitsky
2019-09-06 17:32 ` [Qemu-devel] [PATCH 2/3] block/qcow2: fix the corruption when rebasing luks encrypted files Maxim Levitsky
2019-09-06 19:17 ` Eric Blake
2019-09-06 19:46 ` Maxim Levitsky [this message]
2019-09-09 10:56 ` Kevin Wolf
2019-09-10 11:12 ` [Qemu-devel] [Qemu-stable] " Maxim Levitsky
2019-09-06 17:32 ` [Qemu-devel] [PATCH 3/3] qemu-iotests: test for bz #1745922 Maxim Levitsky
2019-09-06 17:37 ` [Qemu-devel] [PATCH 0/3] Fix qcow2+luks corruption introduced by commit 8ac0f15f335 Maxim Levitsky
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=df8809e370526d5c0eb7987268c185b147855d07.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/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).