qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "John Snow" <jsnow@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [PATCH v7 00/14] LUKS: encryption slot management using amend interface
Date: Sun, 07 Jun 2020 16:06:21 +0300	[thread overview]
Message-ID: <e1abfb5866bb3264dfa8c4ba47d780893f6f81a4.camel@redhat.com> (raw)
In-Reply-To: <3266027d-8baf-a970-3141-3131106ff98c@redhat.com>

On Tue, 2020-06-02 at 18:29 +0200, Max Reitz wrote:
> On 18.05.20 14:20, Maxim Levitsky wrote:
> > Hi!
> > Here is the updated series of my patches, incorporating all the feedback I received.
> 
> You asked me on IRC what to do to get this series to move forward;
> considering I don’t think there were objections from anyone but me on
> v6, there are no further (substantial) objections from anyone on v7, and
> I gave all feedback I had on v6, I don’t think there’s much you can do
> right now.  (Sorry for the delay, but, well, I was on PTO as you know.)
> 
> As usual, I’ll try to get around to see whether I can rebase your series
> myself (because Dan hinted at some conflicts), and whether I feel like
> my comments were appropriately addressed (which I have little doubt
> about).  That’s the plan.
Sorry in advance if I missed any feedback from you. That can happen,
I do make mistakes like anybody of us.


> 
> Note from a couple minutes later: From what I can see, the rebase
> conflicts don’t look too wild, but I don’t feel quite comfortable
> addressing all of them.  There’s a functional one I could address in
> qemu-img.c (patch 3), where we need to bump OPTION_FORCE from 269 to
> 276.  I could do that, but that’s not the only one, unfortunately.
Yes, that conflict is easy.

> 
> Patch 7 needs a bit more extensive modification: First, we need
> %s/bdrv_filter_default_perms/bdrv_default_perms/.  Second, this will
> still not compile, because the .bdrv_child_perm interface has changed.
> BdrvChildRole is now an integer, so we also need
> s/const BdrvChildRole \*/BdrvChildRole /.
> (That gives us the nice side effect of being able to align the second
> line of the bdrv_default_perms() parameters (called from
> block_crypto_child_perms()) on the opening parenthesis.)
I did this.

> 
> Third, it becomes really interesting.  With these changes, it would be
> wrong, because bdrv_default_perms() will then not use the permissions
> for a filter but for an image file with metadata – because that’s what
> the LUKS file child is.
> 
> But that’s actually a bug that’s already there (and that I introduced).
>  It makese sense to fix it in your series here, because to fix it we
> need a dedicated block_crypto_child_perms() function anyway.
> 
> So, well.  Do we want to cheat?  Just let block_crypto_child_perms()
> call bdrv_default_perms() with role=BDRV_CHILD_FILTERED?  That would be
> the previous behavior, but it would also be bad cheating.
> 
> The comment that exists (before patch 7) above
> bdrv_crypto_luks.bdrv_child_perm says that we just want to allow
> share-rw=on, and we could achieve that simply by force-sharing the WRITE
> permission after invoking bdrv_default_perms() with the actual role
> (which is BDRV_CHILD_IMAGE).
> 
> But what about the other stuff that sets
> bdrv_default_perms_for_storage() apart from bdrv_filter_default_perms()?
>  I.e., force-taking WRITE and RESIZE permissions if the file is
> writable; force-taking the CONSISTENT_READ permission because we need
> the metadata; and unsharing the RESIZE permission?
> 
> I think the best thing to do would be to call bdrv_default_perms() with
> the @role passed to block_crypto_child_perms() (i.e., BDRV_CHILD_IMAGE),
> and then relaxing the permissions, that is to share the WRITE and RESIZE
> persmissions, and to perhaps restore the WRITE and RESIZE permissions
> from what’s given to block_crypto_child_perms() (i.e., *nperm &= ~(WRITE
> > RESIZE); *nperm |= perm & (WRITE | RESIZE);), because LUKS doesn’t
> need them unless the image may actually be written.
> 
> (OTOH, force-taking CONSISTENT_READ seems entirely reasonable.)

Could we talk about this on IRC tomorrow? I don't fully understand you here,
and I sort of understood this stuff back when I learned it, but
that was long ago, and since we are talking about permissions here,
plus an necessary hack that luks now have to make, I would like
to understand exactly what I am doing.

Other than that, I rebased the series, and all iotests (with the permission
fix below) are passing.
I'll send the rebased version once we finish the permission thing.


Best regards,
	Maxim Levitsky


PS: This code which is roughtly based on your suggestions,
does pass my test write sharing test, but I don't have much confidence that it is correct:

For example, I don't think that resize permission is needed to be touched,
since resize of the 'luks' image shoudn't have any affect on encryption keys
(since luks image is basically the underlying file minus the header, decrypted,
and we don't really change the encryption key, but a encrypted keyslot which contains it).


    BlockCrypto *crypto = bs->opaque;

    bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nshared);
    /*
     * Ask for consistent read permission so that if
     * someone else tries to open this image with this permission
     * neither will be able to edit encryption keys, since
     * we will unshare that permission while trying to
     * update the encryption keys
     */
    if (!(bs->open_flags & BDRV_O_NO_IO)) {

        *nperm |= BLK_PERM_CONSISTENT_READ;

        *nshared |= (BLK_PERM_WRITE | BLK_PERM_RESIZE);
        *nperm &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
        *nperm |= perm & (BLK_PERM_WRITE | BLK_PERM_RESIZE);
    }
    /*
     * This driver doesn't modify LUKS metadata except
     * when updating the encryption slots.
     * Thus unlike a proper format driver we don't ask for
     * shared write/read permission. However we need it
     * when we are updating the keys, to ensure that only we
     * have access to the device.
     *
     * Encryption update will set the crypto->updating_keys
     * during that period and refresh permissions
     *
     */
    if (crypto->updating_keys) {
        /* need exclusive write access for header update */
        *nperm |= BLK_PERM_WRITE;
        /* unshare read and write permission */
        *nshared &= ~(BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE);
    }




      reply	other threads:[~2020-06-07 13:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 12:20 [PATCH v7 00/14] LUKS: encryption slot management using amend interface Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 01/14] qcrypto/core: add generic infrastructure for crypto options amendment Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 02/14] qcrypto/luks: implement encryption key management Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 03/14] block/amend: add 'force' option Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 04/14] block/amend: separate amend and create options for qemu-img Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 05/14] block/amend: refactor qcow2 amend options Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 06/14] block/crypto: rename two functions Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 07/14] block/crypto: implement the encryption key management Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 08/14] block/qcow2: extend qemu-img amend interface with crypto options Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 09/14] iotests: filter few more luks specific create options Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 10/14] iotests: qemu-img tests for luks key management Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 11/14] block/core: add generic infrastructure for x-blockdev-amend qmp command Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 12/14] block/crypto: implement blockdev-amend Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 13/14] block/qcow2: " Maxim Levitsky
2020-05-18 12:20 ` [PATCH v7 14/14] iotests: add tests for blockdev-amend Maxim Levitsky
2020-05-18 15:50 ` [PATCH v7 00/14] LUKS: encryption slot management using amend interface no-reply
2020-05-18 23:04 ` no-reply
2020-05-29  9:59 ` Daniel P. Berrangé
2020-06-02 16:29 ` Max Reitz
2020-06-07 13:06   ` Maxim Levitsky [this message]

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=e1abfb5866bb3264dfa8c4ba47d780893f6f81a4.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --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).