From nobody Sat Apr 27 23:35:15 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 1520619105351699.3715076284166; Fri, 9 Mar 2018 10:11:45 -0800 (PST) Received: from localhost ([::1]:47142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euMUa-000590-Dp for importer@patchew.org; Fri, 09 Mar 2018 13:11:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLnm-0000pX-MT for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLnl-0006cv-Om for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:30 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44686 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 1euLnj-0006aV-CP; Fri, 09 Mar 2018 12:27:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCCFF4036114; Fri, 9 Mar 2018 17:27:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDD7D2026DFD; Fri, 9 Mar 2018 17:27:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 18:27:08 +0100 Message-Id: <20180309172713.26318-2-kwolf@redhat.com> In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com> References: <20180309172713.26318-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 09 Mar 2018 17:27:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 09 Mar 2018 17:27:22 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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-Transfer-Encoding: quoted-printable MIME-Version: 1.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 Sat Apr 27 23:35:15 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 152061999281549.07988989329033; Fri, 9 Mar 2018 10:26:32 -0800 (PST) Received: from localhost ([::1]:47260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euMiu-0000Bs-0k for importer@patchew.org; Fri, 09 Mar 2018 13:26:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLnm-0000pY-MU for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLnl-0006d0-Ok for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:30 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56902 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 1euLnj-0006aU-CL; Fri, 09 Mar 2018 12:27:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32C8ED143A; Fri, 9 Mar 2018 17:27:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23B5A202660C; Fri, 9 Mar 2018 17:27:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 18:27:09 +0100 Message-Id: <20180309172713.26318-3-kwolf@redhat.com> In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com> References: <20180309172713.26318-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 09 Mar 2018 17:27:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 09 Mar 2018 17:27:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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-Transfer-Encoding: quoted-printable MIME-Version: 1.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 Sat Apr 27 23:35:15 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 1520619837264831.7072158283736; Fri, 9 Mar 2018 10:23:57 -0800 (PST) Received: from localhost ([::1]:47240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euMgJ-00065D-C1 for importer@patchew.org; Fri, 09 Mar 2018 13:23:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLnm-0000pZ-Mx for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLnl-0006cp-LD for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:30 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46862 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 1euLnj-0006aW-CX; Fri, 09 Mar 2018 12:27:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CA4A8011454; Fri, 9 Mar 2018 17:27:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DBD3202660C; Fri, 9 Mar 2018 17:27:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 18:27:10 +0100 Message-Id: <20180309172713.26318-4-kwolf@redhat.com> In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com> References: <20180309172713.26318-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Mar 2018 17:27:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Mar 2018 17:27:25 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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: Eric Blake --- 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..07039bfe9c 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', + 'data': { 'file': 'BlockdevRef', + 'qcrypto': 'QCryptoBlockCreateOptionsLUKS', + '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..2035f9ab13 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 *luks_opts->qcrypto, + }; + + 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 Sat Apr 27 23:35:15 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 1520619696318534.8254712286846; Fri, 9 Mar 2018 10:21:36 -0800 (PST) Received: from localhost ([::1]:47225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euMe7-0004LB-9k for importer@patchew.org; Fri, 09 Mar 2018 13:21:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLnm-0000ot-4T for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLnl-0006cM-Aa for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:30 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35004 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 1euLnj-0006aT-C4; Fri, 09 Mar 2018 12:27:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6C6D406E97D; Fri, 9 Mar 2018 17:27:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7A5B2026DFD; Fri, 9 Mar 2018 17:27:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 18:27:11 +0100 Message-Id: <20180309172713.26318-5-kwolf@redhat.com> In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com> References: <20180309172713.26318-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Mar 2018 17:27:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Mar 2018 17:27:26 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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 2035f9ab13..4908d8627f 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 Sat Apr 27 23:35:15 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 1520620146295909.7403842533545; Fri, 9 Mar 2018 10:29:06 -0800 (PST) Received: from localhost ([::1]:47275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euMlJ-0002RJ-8w for importer@patchew.org; Fri, 09 Mar 2018 13:29:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLnq-0000uW-W2 for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLnm-0006dN-FF for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:34 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45226 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 1euLnk-0006bW-H9; Fri, 09 Mar 2018 12:27:28 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1CCD44129355; Fri, 9 Mar 2018 17:27:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DFEC2024CA1; Fri, 9 Mar 2018 17:27:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 18:27:12 +0100 Message-Id: <20180309172713.26318-6-kwolf@redhat.com> In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com> References: <20180309172713.26318-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 09 Mar 2018 17:27:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 09 Mar 2018 17:27:28 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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-Transfer-Encoding: quoted-printable MIME-Version: 1.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 4908d8627f..1b46519c53 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 (headerlen > UINT64_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 Sat Apr 27 23:35:15 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 1520617562238188.74988865664068; Fri, 9 Mar 2018 09:46:02 -0800 (PST) Received: from localhost ([::1]:46957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euM5h-0008Ka-Cx for importer@patchew.org; Fri, 09 Mar 2018 12:46:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLnu-0000ym-K8 for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euLns-0006fx-Uo for qemu-devel@nongnu.org; Fri, 09 Mar 2018 12:27:38 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35006 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 1euLnl-0006cg-PQ; Fri, 09 Mar 2018 12:27:29 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A329406E8B3; Fri, 9 Mar 2018 17:27:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57FFE202322B; Fri, 9 Mar 2018 17:27:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 18:27:13 +0100 Message-Id: <20180309172713.26318-7-kwolf@redhat.com> In-Reply-To: <20180309172713.26318-1-kwolf@redhat.com> References: <20180309172713.26318-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Mar 2018 17:27:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Mar 2018 17:27:29 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 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: Eric Blake --- tests/qemu-iotests/208 | 211 +++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/208.out | 136 ++++++++++++++++++++++++++++ tests/qemu-iotests/common.rc | 2 +- tests/qemu-iotests/group | 1 + 4 files changed, 349 insertions(+), 1 deletion(-) create mode 100755 tests/qemu-iotests/208 create mode 100644 tests/qemu-iotests/208.out diff --git a/tests/qemu-iotests/208 b/tests/qemu-iotests/208 new file mode 100755 index 0000000000..ab4650d0ae --- /dev/null +++ b/tests/qemu-iotests/208 @@ -0,0 +1,211 @@ +#!/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..574227e761 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 +208 rw auto --=20 2.13.6