thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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