From nobody Wed Nov 12 01:53:57 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567199205; cv=none; d=zoho.com; s=zohoarc; b=RXfMdROH4jjUNSh6uFAg2TUAM0nHMQ/wj8peRcHDrjJge361suVXknQKn2/30BuFXf1CoUH8rIB+t3MxIk5LBwk3h0+wRtL3ojvui10kmvR5B2Yb0qpG8mxh4EAgxuhVLCwXCWOz8/M3fWm3OvpXy09/W6Hgo45rwZhVBazUYZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567199205; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=g2OvoiqbmE1PHGNoe5aaM3pffuh/nicYfvhFoVlvpi8=; b=Xyg9jAAX9a7PGxUTM4YOi5PX4AA76UolOlXAYHjGCAVHWci2E2cayBONE/qDCOo7rJywNS7llr2HrDUIDjYimECCUqH6cMkIsqM5XtMdEhl1aBSaOPGvf7dizpg4CLsXqgnm/izv9JT/EZjYjqYHnsokBQiqj1REGWN4I0zszVc= ARC-Authentication-Results: i=1; mx.zoho.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567199205481647.770978637406; Fri, 30 Aug 2019 14:06:45 -0700 (PDT) Received: from localhost ([::1]:41154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3o6U-0002tw-1u for importer@patchew.org; Fri, 30 Aug 2019 17:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47495) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3nwq-0003JR-1j for qemu-devel@nongnu.org; Fri, 30 Aug 2019 16:56:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3nwo-0001Xn-LZ for qemu-devel@nongnu.org; Fri, 30 Aug 2019 16:56:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i3nwl-0001UQ-Ly; Fri, 30 Aug 2019 16:56:39 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4F80898102; Fri, 30 Aug 2019 20:56:38 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99F735D9CA; Fri, 30 Aug 2019 20:56:36 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Date: Fri, 30 Aug 2019 23:56:04 +0300 Message-Id: <20190830205608.18192-7-mlevitsk@redhat.com> In-Reply-To: <20190830205608.18192-1-mlevitsk@redhat.com> References: <20190830205608.18192-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Fri, 30 Aug 2019 20:56:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/10] qcow2: implement crypto amend options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Maxim Levitsky , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" --- block/qcow2.c | 79 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 376bb416fd..8dff4c6b5f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -171,6 +171,25 @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBloc= k *block, size_t offset, return ret; } =20 +static QCryptoBlockCreateOptions* +qcow2_extract_crypto_create_opts(QemuOpts *opts, const char *fmt, Error **= errp) +{ + QDict *cryptoopts_qdict; + QCryptoBlockCreateOptions *cryptoopts; + QDict *opts_qdict; + + /* Extract "encrypt." options into a qdict */ + opts_qdict =3D qemu_opts_to_qdict(opts, NULL); + qdict_extract_subqdict(opts_qdict, &cryptoopts_qdict, "encrypt."); + qobject_unref(opts_qdict); + + /* Build QCryptoBlockCreateOptions object from qdict */ + qdict_put_str(cryptoopts_qdict, "format", "luks"); + cryptoopts =3D block_crypto_create_opts_init(cryptoopts_qdict, errp); + qobject_unref(cryptoopts_qdict); + return cryptoopts; +} + =20 /*=20 * read qcow2 extension and fill bs @@ -4366,20 +4385,10 @@ static ssize_t qcow2_measure_crypto_hdr_write_func(= QCryptoBlock *block, static bool qcow2_measure_luks_headerlen(QemuOpts *opts, size_t *len, Error **errp) { - QDict *opts_qdict; - QDict *cryptoopts_qdict; QCryptoBlockCreateOptions *cryptoopts; QCryptoBlock *crypto; =20 - /* Extract "encrypt." options into a qdict */ - opts_qdict =3D qemu_opts_to_qdict(opts, NULL); - qdict_extract_subqdict(opts_qdict, &cryptoopts_qdict, "encrypt."); - qobject_unref(opts_qdict); - - /* Build QCryptoBlockCreateOptions object from qdict */ - qdict_put_str(cryptoopts_qdict, "format", "luks"); - cryptoopts =3D block_crypto_create_opts_init(cryptoopts_qdict, errp); - qobject_unref(cryptoopts_qdict); + cryptoopts =3D qcow2_extract_crypto_create_opts(opts, "luks", errp); if (!cryptoopts) { return false; } @@ -4756,6 +4765,7 @@ typedef enum Qcow2AmendOperation { * invocation from an operation change */ QCOW2_NO_OPERATION =3D 0, =20 + QCOW2_UPDATING_ENCRYPTION, QCOW2_CHANGING_REFCOUNT_ORDER, QCOW2_DOWNGRADING, } Qcow2AmendOperation; @@ -4840,6 +4850,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, int ret; QemuOptDesc *desc =3D opts->list->desc; Qcow2AmendHelperCBInfo helper_cb_info; + bool encryption_update =3D false; =20 while (desc && desc->name) { if (!qemu_opt_find(opts, desc->name)) { @@ -4888,9 +4899,22 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, return -ENOTSUP; } } else if (g_str_has_prefix(desc->name, "encrypt.")) { - error_setg(errp, - "Changing the encryption parameters is not supporte= d"); - return -ENOTSUP; + + if (!s->crypto) { + error_setg(errp, + "Can't amend encryption options - encryption no= t supported"); + return -ENOTSUP; + + } + + if (s->crypt_method_header !=3D QCOW_CRYPT_LUKS) { + error_setg(errp, + "Only LUKS encryption options can be amended"); + return -ENOTSUP; + } + + encryption_update =3D true; + } else if (!strcmp(desc->name, BLOCK_OPT_CLUSTER_SIZE)) { cluster_size =3D qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZ= E, cluster_size); @@ -4927,7 +4951,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, "images"); return -EINVAL; } - } else { + } else { /* if this point is reached, this probably means a new option = was * added without having it covered here */ abort(); @@ -4940,7 +4964,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, .original_status_cb =3D status_cb, .original_cb_opaque =3D cb_opaque, .total_operations =3D (new_version < old_version) - + (s->refcount_bits !=3D refcount_bits) + + (s->refcount_bits !=3D refcount_bits) + + (encryption_update =3D=3D true) }; =20 /* Upgrade first (some features may require compat=3D1.1) */ @@ -4954,6 +4979,28 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, } } =20 + if (encryption_update) { + + QCryptoBlockCreateOptions *cryptoopts; + + cryptoopts =3D qcow2_extract_crypto_create_opts(opts, "luks", errp= ); + if (!cryptoopts) + return -EINVAL; + + helper_cb_info.current_operation =3D QCOW2_UPDATING_ENCRYPTION; + + ret =3D qcrypto_block_amend_options(s->crypto, + qcow2_crypto_hdr_read_func, + qcow2_crypto_hdr_write_func, + bs, + cryptoopts, + force, + errp); + if (ret) { + return ret; + } + } + if (s->refcount_bits !=3D refcount_bits) { int refcount_order =3D ctz32(refcount_bits); =20 --=20 2.17.2