From nobody Wed May 8 16:56:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520867405950934.1786812115372; Mon, 12 Mar 2018 08:10:05 -0700 (PDT) Received: from localhost ([::1]:59417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evP5R-0001ur-3x for importer@patchew.org; Mon, 12 Mar 2018 11:10:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evOyM-0004gi-7H for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evOyH-0002rx-CI for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33292 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evOy5-0002ex-1h; Mon, 12 Mar 2018 11:02:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 891FDC33F; Mon, 12 Mar 2018 15:02:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79914215CDAF; Mon, 12 Mar 2018 15:02:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 12 Mar 2018 16:02:13 +0100 Message-Id: <20180312150218.1314-2-kwolf@redhat.com> In-Reply-To: <20180312150218.1314-1-kwolf@redhat.com> References: <20180312150218.1314-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:28 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 1/6] luks: Separate image file creation from formatting 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The crypto driver used to create the image file in a callback from the crypto subsystem. If we want to implement .bdrv_co_create, this needs to go away because that callback will get a reference to an already existing block node. Move the image file creation to block_crypto_create_generic(). Signed-off-by: Kevin Wolf Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- block/crypto.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index e6095e7807..77871640cc 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -71,8 +71,6 @@ static ssize_t block_crypto_read_func(QCryptoBlock *block, =20 =20 struct BlockCryptoCreateData { - const char *filename; - QemuOpts *opts; BlockBackend *blk; uint64_t size; }; @@ -103,27 +101,13 @@ static ssize_t block_crypto_init_func(QCryptoBlock *b= lock, Error **errp) { struct BlockCryptoCreateData *data =3D opaque; - int ret; =20 /* User provided size should reflect amount of space made * available to the guest, so we must take account of that * which will be used by the crypto header */ - data->size +=3D headerlen; - - qemu_opt_set_number(data->opts, BLOCK_OPT_SIZE, data->size, &error_abo= rt); - ret =3D bdrv_create_file(data->filename, data->opts, errp); - if (ret < 0) { - return -1; - } - - data->blk =3D blk_new_open(data->filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_PROTOCOL, errp); - if (!data->blk) { - return -1; - } - - return 0; + return blk_truncate(data->blk, data->size + headerlen, PREALLOC_MODE_O= FF, + errp); } =20 =20 @@ -333,11 +317,10 @@ static int block_crypto_create_generic(QCryptoBlockFo= rmat format, struct BlockCryptoCreateData data =3D { .size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE), - .opts =3D opts, - .filename =3D filename, }; QDict *cryptoopts; =20 + /* Parse options */ cryptoopts =3D qemu_opts_to_qdict(opts, NULL); =20 create_opts =3D block_crypto_create_opts_init(format, cryptoopts, errp= ); @@ -345,6 +328,20 @@ static int block_crypto_create_generic(QCryptoBlockFor= mat format, return -1; } =20 + /* Create protocol layer */ + ret =3D bdrv_create_file(filename, opts, errp); + if (ret < 0) { + return ret; + } + + data.blk =3D blk_new_open(filename, NULL, NULL, + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, + errp); + if (!data.blk) { + return -EINVAL; + } + + /* Create format layer */ crypto =3D qcrypto_block_create(create_opts, NULL, block_crypto_init_func, block_crypto_write_func, --=20 2.13.6 From nobody Wed May 8 16:56:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520867156867840.4105326377966; Mon, 12 Mar 2018 08:05:56 -0700 (PDT) Received: from localhost ([::1]:59393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evP1P-000759-El for importer@patchew.org; Mon, 12 Mar 2018 11:05:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evOyP-0004ih-8F for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evOyJ-0002tp-Cy for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42998 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evOy6-0002gC-AI; Mon, 12 Mar 2018 11:02:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3A274023BB3; Mon, 12 Mar 2018 15:02:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id C35F8215CDAF; Mon, 12 Mar 2018 15:02:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 12 Mar 2018 16:02:14 +0100 Message-Id: <20180312150218.1314-3-kwolf@redhat.com> In-Reply-To: <20180312150218.1314-1-kwolf@redhat.com> References: <20180312150218.1314-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 12 Mar 2018 15:02:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 12 Mar 2018 15:02:29 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/6] luks: Create block_crypto_co_create_generic() 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Everything that refers to the protocol layer or QemuOpts is moved out of block_crypto_create_generic(), so that the remaining function is suitable to be called by a .bdrv_co_create implementation. LUKS is the only driver that actually implements the old interface, and we don't intend to use it in any new drivers, so put the moved out code directly into a LUKS function rather than creating a generic intermediate one. Signed-off-by: Kevin Wolf Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- block/crypto.c | 95 +++++++++++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 77871640cc..b0a4cb3388 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -306,43 +306,29 @@ static int block_crypto_open_generic(QCryptoBlockForm= at format, } =20 =20 -static int block_crypto_create_generic(QCryptoBlockFormat format, - const char *filename, - QemuOpts *opts, - Error **errp) +static int block_crypto_co_create_generic(BlockDriverState *bs, + int64_t size, + QCryptoBlockCreateOptions *opts, + Error **errp) { - int ret =3D -EINVAL; - QCryptoBlockCreateOptions *create_opts =3D NULL; + int ret; + BlockBackend *blk; QCryptoBlock *crypto =3D NULL; - struct BlockCryptoCreateData data =3D { - .size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE), - }; - QDict *cryptoopts; - - /* Parse options */ - cryptoopts =3D qemu_opts_to_qdict(opts, NULL); + struct BlockCryptoCreateData data; =20 - create_opts =3D block_crypto_create_opts_init(format, cryptoopts, errp= ); - if (!create_opts) { - return -1; - } + blk =3D blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL); =20 - /* Create protocol layer */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { - return ret; + goto cleanup; } =20 - data.blk =3D blk_new_open(filename, NULL, NULL, - BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, - errp); - if (!data.blk) { - return -EINVAL; - } + data =3D (struct BlockCryptoCreateData) { + .blk =3D blk, + .size =3D size, + }; =20 - /* Create format layer */ - crypto =3D qcrypto_block_create(create_opts, NULL, + crypto =3D qcrypto_block_create(opts, NULL, block_crypto_init_func, block_crypto_write_func, &data, @@ -355,10 +341,8 @@ static int block_crypto_create_generic(QCryptoBlockFor= mat format, =20 ret =3D 0; cleanup: - QDECREF(cryptoopts); qcrypto_block_free(crypto); - blk_unref(data.blk); - qapi_free_QCryptoBlockCreateOptions(create_opts); + blk_unref(blk); return ret; } =20 @@ -563,8 +547,51 @@ static int coroutine_fn block_crypto_co_create_opts_lu= ks(const char *filename, QemuOpts *opts, Error **errp) { - return block_crypto_create_generic(Q_CRYPTO_BLOCK_FORMAT_LUKS, - filename, opts, errp); + QCryptoBlockCreateOptions *create_opts =3D NULL; + BlockDriverState *bs =3D NULL; + QDict *cryptoopts; + int64_t size; + int ret; + + /* Parse options */ + size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + + cryptoopts =3D qemu_opts_to_qdict_filtered(opts, NULL, + &block_crypto_create_opts_luk= s, + true); + + create_opts =3D block_crypto_create_opts_init(Q_CRYPTO_BLOCK_FORMAT_LU= KS, + cryptoopts, errp); + if (!create_opts) { + ret =3D -EINVAL; + goto fail; + } + + /* Create protocol layer */ + ret =3D bdrv_create_file(filename, opts, errp); + if (ret < 0) { + return ret; + } + + bs =3D bdrv_open(filename, NULL, NULL, + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp); + if (!bs) { + ret =3D -EINVAL; + goto fail; + } + + /* Create format layer */ + ret =3D block_crypto_co_create_generic(bs, size, create_opts, errp); + if (ret < 0) { + goto fail; + } + + ret =3D 0; +fail: + bdrv_unref(bs); + qapi_free_QCryptoBlockCreateOptions(create_opts); + QDECREF(cryptoopts); + return ret; } =20 static int block_crypto_get_info_luks(BlockDriverState *bs, --=20 2.13.6 From nobody Wed May 8 16:56:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520867525215275.4280901737392; Mon, 12 Mar 2018 08:12:05 -0700 (PDT) Received: from localhost ([::1]:59437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evP7M-0003iO-Ci for importer@patchew.org; Mon, 12 Mar 2018 11:12:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evOyT-0004oS-MG for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evOyN-0002zs-QV for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33296 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evOy7-0002hG-KJ; Mon, 12 Mar 2018 11:02:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AC83C33F; Mon, 12 Mar 2018 15:02:31 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AAA1215CDAE; Mon, 12 Mar 2018 15:02:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 12 Mar 2018 16:02:15 +0100 Message-Id: <20180312150218.1314-4-kwolf@redhat.com> In-Reply-To: <20180312150218.1314-1-kwolf@redhat.com> References: <20180312150218.1314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:31 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/6] luks: Support .bdrv_co_create 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This adds the .bdrv_co_create driver callback to luks, which enables image creation over QMP. Signed-off-by: Kevin Wolf Reviewed-by: Daniel P. Berrang=C3=A9 --- qapi/block-core.json | 17 ++++++++++++++++- block/crypto.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 524d51567a..751adf89f4 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3452,6 +3452,21 @@ '*preallocation': 'PreallocMode' } } =20 ## +# @BlockdevCreateOptionsLUKS: +# +# Driver specific image creation options for LUKS. +# +# @file Node to create the image format on +# @size Size of the virtual disk in bytes +# +# Since: 2.12 +## +{ 'struct': 'BlockdevCreateOptionsLUKS', + 'base': 'QCryptoBlockCreateOptionsLUKS', + 'data': { 'file': 'BlockdevRef', + 'size': 'size' } } + +## # @BlockdevCreateOptionsNfs: # # Driver specific image creation options for NFS. @@ -3643,7 +3658,7 @@ 'http': 'BlockdevCreateNotSupported', 'https': 'BlockdevCreateNotSupported', 'iscsi': 'BlockdevCreateNotSupported', - 'luks': 'BlockdevCreateNotSupported', + 'luks': 'BlockdevCreateOptionsLUKS', 'nbd': 'BlockdevCreateNotSupported', 'nfs': 'BlockdevCreateOptionsNfs', 'null-aio': 'BlockdevCreateNotSupported', diff --git a/block/crypto.c b/block/crypto.c index b0a4cb3388..a1139b6f09 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -543,6 +543,39 @@ static int block_crypto_open_luks(BlockDriverState *bs, bs, options, flags, errp); } =20 +static int coroutine_fn +block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error *= *errp) +{ + BlockdevCreateOptionsLUKS *luks_opts; + BlockDriverState *bs =3D NULL; + QCryptoBlockCreateOptions create_opts; + int ret; + + assert(create_options->driver =3D=3D BLOCKDEV_DRIVER_LUKS); + luks_opts =3D &create_options->u.luks; + + bs =3D bdrv_open_blockdev_ref(luks_opts->file, errp); + if (bs =3D=3D NULL) { + return -EIO; + } + + create_opts =3D (QCryptoBlockCreateOptions) { + .format =3D Q_CRYPTO_BLOCK_FORMAT_LUKS, + .u.luks =3D *qapi_BlockdevCreateOptionsLUKS_base(luks_opts), + }; + + ret =3D block_crypto_co_create_generic(bs, luks_opts->size, &create_op= ts, + errp); + if (ret < 0) { + goto fail; + } + + ret =3D 0; +fail: + bdrv_unref(bs); + return ret; +} + static int coroutine_fn block_crypto_co_create_opts_luks(const char *filen= ame, QemuOpts *opts, Error **errp) @@ -647,6 +680,7 @@ BlockDriver bdrv_crypto_luks =3D { .bdrv_open =3D block_crypto_open_luks, .bdrv_close =3D block_crypto_close, .bdrv_child_perm =3D bdrv_format_default_perms, + .bdrv_co_create =3D block_crypto_co_create_luks, .bdrv_co_create_opts =3D block_crypto_co_create_opts_luks, .bdrv_truncate =3D block_crypto_truncate, .create_opts =3D &block_crypto_create_opts_luks, --=20 2.13.6 From nobody Wed May 8 16:56:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520867630637880.5061382875474; Mon, 12 Mar 2018 08:13:50 -0700 (PDT) Received: from localhost ([::1]:59448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evP93-0004xY-OY for importer@patchew.org; Mon, 12 Mar 2018 11:13:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evOyP-0004ii-9Q for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evOyJ-0002ty-IG for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33298 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evOy8-0002iV-UQ; Mon, 12 Mar 2018 11:02:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7AB08C33F; Mon, 12 Mar 2018 15:02:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 654082166BAE; Mon, 12 Mar 2018 15:02:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 12 Mar 2018 16:02:16 +0100 Message-Id: <20180312150218.1314-5-kwolf@redhat.com> In-Reply-To: <20180312150218.1314-1-kwolf@redhat.com> References: <20180312150218.1314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:32 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 4/6] luks: Turn invalid assertion into check 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The .bdrv_getlength implementation of the crypto block driver asserted that the payload offset isn't after EOF. This is an invalid assertion to make as the image file could be corrupted. Instead, check it and return -EIO if the file is too small for the payload offset. Zero length images are fine, so trigger -EIO only on offset > len, not on offset >=3D len as the assertion did before. Signed-off-by: Kevin Wolf Reviewed-by: Daniel P. Berrang=C3=A9 --- block/crypto.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/crypto.c b/block/crypto.c index a1139b6f09..16c371ec9c 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -518,7 +518,10 @@ static int64_t block_crypto_getlength(BlockDriverState= *bs) =20 uint64_t offset =3D qcrypto_block_get_payload_offset(crypto->block); assert(offset < INT64_MAX); - assert(offset < len); + + if (offset > len) { + return -EIO; + } =20 len -=3D offset; =20 --=20 2.13.6 From nobody Wed May 8 16:56:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520867093877749.2844666711941; Mon, 12 Mar 2018 08:04:53 -0700 (PDT) Received: from localhost ([::1]:59384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evP0O-0006DI-RZ for importer@patchew.org; Mon, 12 Mar 2018 11:04:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evOyK-0004eV-BL for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evOyJ-0002u8-KA for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33300 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evOyA-0002jt-A3; Mon, 12 Mar 2018 11:02:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C61F4C33F; Mon, 12 Mar 2018 15:02:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id B51EF215CDAC; Mon, 12 Mar 2018 15:02:32 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 12 Mar 2018 16:02:17 +0100 Message-Id: <20180312150218.1314-6-kwolf@redhat.com> In-Reply-To: <20180312150218.1314-1-kwolf@redhat.com> References: <20180312150218.1314-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 12 Mar 2018 15:02:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 5/6] luks: Catch integer overflow for huge sizes 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When you request an image size close to UINT64_MAX, the addition of the crypto header may cause an integer overflow. Catch it instead of silently truncating the image size. Signed-off-by: Kevin Wolf Reviewed-by: Daniel P. Berrang=C3=A9 --- block/crypto.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/crypto.c b/block/crypto.c index 16c371ec9c..9dac08c6c5 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -102,6 +102,11 @@ static ssize_t block_crypto_init_func(QCryptoBlock *bl= ock, { struct BlockCryptoCreateData *data =3D opaque; =20 + if (data->size > INT64_MAX || headerlen > INT64_MAX - data->size) { + error_setg(errp, "The requested file size is too large"); + return -EFBIG; + } + /* User provided size should reflect amount of space made * available to the guest, so we must take account of that * which will be used by the crypto header --=20 2.13.6 From nobody Wed May 8 16:56:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520867506767640.5309643884048; Mon, 12 Mar 2018 08:11:46 -0700 (PDT) Received: from localhost ([::1]:59435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evP73-0003UD-Vk for importer@patchew.org; Mon, 12 Mar 2018 11:11:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evOyS-0004nT-GW for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evOyL-0002x8-Sd for qemu-devel@nongnu.org; Mon, 12 Mar 2018 11:02:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43008 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evOyB-0002l7-Ii; Mon, 12 Mar 2018 11:02:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D25D4000B6E; Mon, 12 Mar 2018 15:02:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D0D1215CDAC; Mon, 12 Mar 2018 15:02:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 12 Mar 2018 16:02:18 +0100 Message-Id: <20180312150218.1314-7-kwolf@redhat.com> In-Reply-To: <20180312150218.1314-1-kwolf@redhat.com> References: <20180312150218.1314-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 12 Mar 2018 15:02:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 12 Mar 2018 15:02:35 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 6/6] qemu-iotests: Test luks QMP image creation 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/qemu-iotests/209 | 210 +++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/209.out | 136 ++++++++++++++++++++++++++++ tests/qemu-iotests/common.rc | 2 +- tests/qemu-iotests/group | 1 + 4 files changed, 348 insertions(+), 1 deletion(-) create mode 100755 tests/qemu-iotests/209 create mode 100644 tests/qemu-iotests/209.out diff --git a/tests/qemu-iotests/209 b/tests/qemu-iotests/209 new file mode 100755 index 0000000000..96a5213e77 --- /dev/null +++ b/tests/qemu-iotests/209 @@ -0,0 +1,210 @@ +#!/bin/bash +# +# Test luks and file image creation +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dkwolf@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +status=3D1 # failure is the default! + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt luks +_supported_proto file +_supported_os Linux + +function do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +function run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ + | _filter_qemu | _filter_imgfmt \ + | _filter_actual_image_size +} + +echo +echo "=3D=3D=3D Successful image creation (defaults) =3D=3D=3D" +echo + +size=3D$((128 * 1024 * 1024)) + +run_qemu -object secret,id=3Dkeysec0,data=3D"foo" <&1 | \ + $QEMU_IMG info $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \ sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ -e "s#$TEST_DIR#TEST_DIR#g" \ -e "s#$IMGFMT#IMGFMT#g" \ diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index c401791fcd..b8d0fd6177 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -204,3 +204,4 @@ 205 rw auto quick 206 rw auto 207 rw auto +209 rw auto --=20 2.13.6