From nobody Fri Dec 19 20:12:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554153090946767.5161104904; Mon, 1 Apr 2019 14:11:30 -0700 (PDT) Received: from localhost ([127.0.0.1]:39854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB4DA-0000Ne-GS for importer@patchew.org; Mon, 01 Apr 2019 17:11:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hB442-0000um-Nv for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:01:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hB441-00038c-IG for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:01:54 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43376 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hB441-00038A-9z for qemu-devel@nongnu.org; Mon, 01 Apr 2019 17:01:53 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x31L1p1l095691 for ; Mon, 1 Apr 2019 17:01:52 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rkswegv8j-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 01 Apr 2019 17:01:52 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 1 Apr 2019 22:01:46 +0100 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 1 Apr 2019 22:01:44 +0100 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x31L1hbe25231446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Apr 2019 21:01:43 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BD167BE056; Mon, 1 Apr 2019 21:01:43 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94F6EBE051; Mon, 1 Apr 2019 21:01:43 +0000 (GMT) Received: from localhost (unknown [9.80.94.43]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 1 Apr 2019 21:01:43 +0000 (GMT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 1 Apr 2019 15:58:53 -0500 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190401210011.16009-1-mdroth@linux.vnet.ibm.com> References: <20190401210011.16009-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19040121-8235-0000-0000-00000E781E5E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010857; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000283; SDB=6.01182941; UDB=6.00619269; IPR=6.00963683; MB=3.00026249; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-01 21:01:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19040121-8236-0000-0000-000044FDC015 Message-Id: <20190401210011.16009-20-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-01_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904010136 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id x31L1p1l095691 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 19/97] qemu-img: fix regression copying secrets during convert X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Daniel P. Berrang=C3=A9 When the convert command is creating an output file that needs secrets, we need to ensure those secrets are passed to both the blk_new_open and bdrv_create API calls. This is done by qemu-img extracting all opts matching the name suffix "key-secret". Unfortunately the code doing this was run after the call to bdrv_create(), which meant the QemuOpts it was extracting secrets from was now empty. Previously this worked by luks as a bug meant the "key-secret" parameters were not purged from the QemuOpts. This bug was fixed in commit b76b4f604521e59f857d6177bc55f6f2e41fd392 Author: Kevin Wolf Date: Thu Jan 11 16:18:08 2018 +0100 qcow2: Use visitor for options in qcow2_create() Exposing the latent bug in qemu-img. This fix simply moves the copying of secrets to before the bdrv_create() call. Cc: qemu-stable@nongnu.org Signed-off-by: Daniel P. Berrang=C3=A9 Signed-off-by: Kevin Wolf (cherry picked from commit 8d65a3ccfd5db7f0436e095cd952f5d0c3a873ba) Signed-off-by: Michael Roth --- qemu-img.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 1acddf693c..b12f4cd19b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -345,21 +345,6 @@ static int img_add_key_secrets(void *opaque, return 0; } =20 -static BlockBackend *img_open_new_file(const char *filename, - QemuOpts *create_opts, - const char *fmt, int flags, - bool writethrough, bool quiet, - bool force_share) -{ - QDict *options =3D NULL; - - options =3D qdict_new(); - qemu_opt_foreach(create_opts, img_add_key_secrets, options, &error_abo= rt); - - return img_open_file(filename, options, fmt, flags, writethrough, quie= t, - force_share); -} - =20 static BlockBackend *img_open(bool image_opts, const char *filename, @@ -2018,6 +2003,7 @@ static int img_convert(int argc, char **argv) BlockDriverState *out_bs; QemuOpts *opts =3D NULL, *sn_opts =3D NULL; QemuOptsList *create_opts =3D NULL; + QDict *open_opts =3D NULL; char *options =3D NULL; Error *local_err =3D NULL; bool writethrough, src_writethrough, quiet =3D false, image_opts =3D f= alse, @@ -2362,6 +2348,16 @@ static int img_convert(int argc, char **argv) } } =20 + /* + * The later open call will need any decryption secrets, and + * bdrv_create() will purge "opts", so extract them now before + * they are lost. + */ + if (!skip_create) { + open_opts =3D qdict_new(); + qemu_opt_foreach(opts, img_add_key_secrets, open_opts, &error_abor= t); + } + if (!skip_create) { /* Create the new image */ ret =3D bdrv_create(drv, out_filename, opts, &local_err); @@ -2388,8 +2384,9 @@ static int img_convert(int argc, char **argv) * That has to wait for bdrv_create to be improved * to allow filenames in option syntax */ - s.target =3D img_open_new_file(out_filename, opts, out_fmt, - flags, writethrough, quiet, false); + s.target =3D img_open_file(out_filename, open_opts, out_fmt, + flags, writethrough, quiet, false); + open_opts =3D NULL; /* blk_new_open will have freed it */ } if (!s.target) { ret =3D -1; @@ -2464,6 +2461,7 @@ out: qemu_opts_del(opts); qemu_opts_free(create_opts); qemu_opts_del(sn_opts); + qobject_unref(open_opts); blk_unref(s.target); if (s.src) { for (bs_i =3D 0; bs_i < s.src_num; bs_i++) { --=20 2.17.1