qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Max Reitz <mreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
	Eric Blake <eblake@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 13/18] qcow2: add support for LUKS encryption format
Date: Mon, 20 Feb 2017 18:18:13 +0000	[thread overview]
Message-ID: <20170220181813.GC15874@redhat.com> (raw)
In-Reply-To: <w5160kackwj.fsf@maestria.local.igalia.com>

On Thu, Feb 16, 2017 at 02:42:04PM +0100, Alberto Garcia wrote:
> On Fri 10 Feb 2017 06:09:05 PM CET, Daniel P. Berrange wrote:
> > @@ -990,12 +1123,6 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
> >      s->refcount_max = UINT64_C(1) << (s->refcount_bits - 1);
> >      s->refcount_max += s->refcount_max - 1;
> >  
> > -    if (header.crypt_method > QCOW_CRYPT_AES) {
> > -        error_setg(errp, "Unsupported encryption method: %" PRIu32,
> > -                   header.crypt_method);
> > -        ret = -EINVAL;
> > -        goto fail;
> > -    }
> 
> Here you remove the check for a valid encryption method...
> 
> >      s->crypt_method_header = header.crypt_method;
> >      if (s->crypt_method_header) {
> >          if (bdrv_uses_whitelist() &&
> > @@ -1012,6 +1139,12 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
> >              goto fail;
> >          }
> >  
> > +        if (s->crypt_method_header == QCOW_CRYPT_AES) {
> > +            s->crypt_physical_offset = false;
> > +        } else {
> > +            s->crypt_physical_offset = true;
> > +        }
> > +
> 
> ...and here you assume that if it's not AES then it must be LUKS.
> However at this point crypt_method_header hasn't been verified yet and
> can have any value.
> 
> The image will fail to open anyway because of the qcow2_update_options()
> call later in this function, but I think it wouldn't hurt to have an
> explicit check here, or at least an explanatory comment.

Yes, we're assuming LUKS and any future scheme we implement will
use the else{} code path, the first path is insecure.

> 
> > +static int qcow2_crypt_method_from_format(const char *format)
> > +{
> > +    if (g_str_equal(format, "luks")) {
> > +        return QCOW_CRYPT_LUKS;
> > +    } else if (g_str_equal(format, "aes")) {
> > +        return QCOW_CRYPT_AES;
> > +    } else {
> > +        return -EINVAL;
> > +    }
> > +}
> >  
> >  static int qcow2_set_up_encryption(BlockDriverState *bs, QemuOpts *opts,
> > -                                   Error **errp)
> > +                                   const char *format, Error **errp)
> >  {
> >      BDRVQcow2State *s = bs->opaque;
> >      QCryptoBlockCreateOptions *cryptoopts = NULL;
> >      QCryptoBlock *crypto = NULL;
> >      int ret = -EINVAL;
> >  
> > -    cryptoopts = block_crypto_create_opts_init(
> > -        Q_CRYPTO_BLOCK_FORMAT_QCOW, opts, "aes-", errp);
> > +    if (g_str_equal(format, "luks")) {
> > +        cryptoopts = block_crypto_create_opts_init(
> > +            Q_CRYPTO_BLOCK_FORMAT_LUKS, opts, "luks-", errp);
> > +        s->crypt_method_header = QCOW_CRYPT_LUKS;
> > +    } else if (g_str_equal(format, "aes")) {
> > +        cryptoopts = block_crypto_create_opts_init(
> > +            Q_CRYPTO_BLOCK_FORMAT_QCOW, opts, "aes-", errp);
> > +        s->crypt_method_header = QCOW_CRYPT_AES;
> > +    } else {
> 
> You just added a nice qcow2_crypt_method_from_format() function
> immediately before this one, I think this one would be more readable if
> you use it here.

Yes, it lets us turn it into a nicer switch()


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|

  reply	other threads:[~2017-02-20 18:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 17:08 [Qemu-devel] [PATCH v4 00/18] Convert QCow[2] to QCryptoBlock & add LUKS support Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 01/18] block: expose crypto option names / defs to other drivers Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 02/18] block: add ability to set a prefix for opt names Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 03/18] qcow: document another weakness of qcow AES encryption Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 04/18] qcow: require image size to be > 1 for new images Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 05/18] iotests: skip 042 with qcow which dosn't support zero sized images Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 06/18] iotests: skip 048 with qcow which doesn't support resize Daniel P. Berrange
2017-02-10 17:08 ` [Qemu-devel] [PATCH v4 07/18] iotests: fix 097 when run with qcow Daniel P. Berrange
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 08/18] qcow: make encrypt_sectors encrypt in place Daniel P. Berrange
2017-02-13 10:47   ` Alberto Garcia
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 09/18] qcow: convert QCow to use QCryptoBlock for encryption Daniel P. Berrange
2017-02-13 14:53   ` Alberto Garcia
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 10/18] qcow2: make qcow2_encrypt_sectors encrypt in place Daniel P. Berrange
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 11/18] qcow2: convert QCow2 to use QCryptoBlock for encryption Daniel P. Berrange
2017-02-12  2:36   ` Max Reitz
2017-02-15 14:29   ` Alberto Garcia
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 12/18] qcow2: extend specification to cover LUKS encryption Daniel P. Berrange
2017-02-15 15:18   ` Alberto Garcia
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 13/18] qcow2: add support for LUKS encryption format Daniel P. Berrange
2017-02-16 13:42   ` Alberto Garcia
2017-02-20 18:18     ` Daniel P. Berrange [this message]
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 14/18] qcow2: add iotests to cover LUKS encryption support Daniel P. Berrange
2017-02-16 13:51   ` Alberto Garcia
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 15/18] iotests: enable tests 134 and 158 to work with qcow (v1) Daniel P. Berrange
2017-02-15 15:39   ` Alberto Garcia
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 16/18] block: rip out all traces of password prompting Daniel P. Berrange
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 17/18] block: remove all encryption handling APIs Daniel P. Berrange
2017-02-10 17:09 ` [Qemu-devel] [PATCH v4 18/18] block: pass option prefix down to crypto layer Daniel P. Berrange
2017-02-12  2:39   ` Max Reitz

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=20170220181813.GC15874@redhat.com \
    --to=berrange@redhat.com \
    --cc=berto@igalia.com \
    --cc=eblake@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).