Blame SOURCES/kvm-qemu-img-fix-regression-copying-secrets-during-conve.patch

383d26
From c8b73d0f85b2435aabbdec92452cb7a0446b1d36 Mon Sep 17 00:00:00 2001
383d26
From: Kevin Wolf <kwolf@redhat.com>
383d26
Date: Mon, 3 Sep 2018 09:41:40 +0200
383d26
Subject: [PATCH 27/29] qemu-img: fix regression copying secrets during convert
383d26
MIME-Version: 1.0
383d26
Content-Type: text/plain; charset=UTF-8
383d26
Content-Transfer-Encoding: 8bit
383d26
383d26
RH-Author: Kevin Wolf <kwolf@redhat.com>
383d26
Message-id: <20180903094140.12988-2-kwolf@redhat.com>
383d26
Patchwork-id: 82031
383d26
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/1] qemu-img: fix regression copying secrets during convert
383d26
Bugzilla: 1575578
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Daniel P. Berrange <berrange@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
From: Daniel P. Berrangé <berrange@redhat.com>
383d26
383d26
When the convert command is creating an output file that needs
383d26
secrets, we need to ensure those secrets are passed to both the
383d26
blk_new_open and bdrv_create API calls.
383d26
383d26
This is done by qemu-img extracting all opts matching the name
383d26
suffix "key-secret". Unfortunately the code doing this was run after the
383d26
call to bdrv_create(), which meant the QemuOpts it was extracting
383d26
secrets from was now empty.
383d26
383d26
Previously this worked by luks as a bug meant the "key-secret"
383d26
parameters were not purged from the QemuOpts. This bug was fixed in
383d26
383d26
  commit b76b4f604521e59f857d6177bc55f6f2e41fd392
383d26
  Author: Kevin Wolf <kwolf@redhat.com>
383d26
  Date:   Thu Jan 11 16:18:08 2018 +0100
383d26
383d26
    qcow2: Use visitor for options in qcow2_create()
383d26
383d26
Exposing the latent bug in qemu-img. This fix simply moves the copying
383d26
of secrets to before the bdrv_create() call.
383d26
383d26
Cc: qemu-stable@nongnu.org
383d26
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
(cherry picked from commit 8d65a3ccfd5db7f0436e095cd952f5d0c3a873ba)
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 qemu-img.c | 32 +++++++++++++++-----------------
383d26
 1 file changed, 15 insertions(+), 17 deletions(-)
383d26
383d26
diff --git a/qemu-img.c b/qemu-img.c
383d26
index f42750a..fa0cbd7 100644
383d26
--- a/qemu-img.c
383d26
+++ b/qemu-img.c
383d26
@@ -348,21 +348,6 @@ static int img_add_key_secrets(void *opaque,
383d26
     return 0;
383d26
 }
383d26
 
383d26
-static BlockBackend *img_open_new_file(const char *filename,
383d26
-                                       QemuOpts *create_opts,
383d26
-                                       const char *fmt, int flags,
383d26
-                                       bool writethrough, bool quiet,
383d26
-                                       bool force_share)
383d26
-{
383d26
-    QDict *options = NULL;
383d26
-
383d26
-    options = qdict_new();
383d26
-    qemu_opt_foreach(create_opts, img_add_key_secrets, options, &error_abort);
383d26
-
383d26
-    return img_open_file(filename, options, fmt, flags, writethrough, quiet,
383d26
-                         force_share);
383d26
-}
383d26
-
383d26
 
383d26
 static BlockBackend *img_open(bool image_opts,
383d26
                               const char *filename,
383d26
@@ -1994,6 +1979,7 @@ static int img_convert(int argc, char **argv)
383d26
     BlockDriverState *out_bs;
383d26
     QemuOpts *opts = NULL, *sn_opts = NULL;
383d26
     QemuOptsList *create_opts = NULL;
383d26
+    QDict *open_opts = NULL;
383d26
     char *options = NULL;
383d26
     Error *local_err = NULL;
383d26
     bool writethrough, src_writethrough, quiet = false, image_opts = false,
383d26
@@ -2342,6 +2328,16 @@ static int img_convert(int argc, char **argv)
383d26
         }
383d26
     }
383d26
 
383d26
+    /*
383d26
+     * The later open call will need any decryption secrets, and
383d26
+     * bdrv_create() will purge "opts", so extract them now before
383d26
+     * they are lost.
383d26
+     */
383d26
+    if (!skip_create) {
383d26
+        open_opts = qdict_new();
383d26
+        qemu_opt_foreach(opts, img_add_key_secrets, open_opts, &error_abort);
383d26
+    }
383d26
+
383d26
     if (!skip_create) {
383d26
         /* Create the new image */
383d26
         ret = bdrv_create(drv, out_filename, opts, &local_err);
383d26
@@ -2368,8 +2364,9 @@ static int img_convert(int argc, char **argv)
383d26
          * That has to wait for bdrv_create to be improved
383d26
          * to allow filenames in option syntax
383d26
          */
383d26
-        s.target = img_open_new_file(out_filename, opts, out_fmt,
383d26
-                                     flags, writethrough, quiet, false);
383d26
+        s.target = img_open_file(out_filename, open_opts, out_fmt,
383d26
+                                 flags, writethrough, quiet, false);
383d26
+        open_opts = NULL; /* blk_new_open will have freed it */
383d26
     }
383d26
     if (!s.target) {
383d26
         ret = -1;
383d26
@@ -2437,6 +2434,7 @@ out:
383d26
     qemu_opts_del(opts);
383d26
     qemu_opts_free(create_opts);
383d26
     qemu_opts_del(sn_opts);
383d26
+    qobject_unref(open_opts);
383d26
     blk_unref(s.target);
383d26
     if (s.src) {
383d26
         for (bs_i = 0; bs_i < s.src_num; bs_i++) {
383d26
-- 
383d26
1.8.3.1
383d26