From nobody Wed Apr 24 03:36:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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; dkim=fail; spf=pass (zohomail.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 1581614301237502.7958817668422; Thu, 13 Feb 2020 09:18:21 -0800 (PST) Received: from localhost ([::1]:56256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2I83-0006Bp-7m for importer@patchew.org; Thu, 13 Feb 2020 12:18:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33297) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2I76-0005dN-Np for qemu-devel@nongnu.org; Thu, 13 Feb 2020 12:17:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2I75-000408-H1 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 12:17:20 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:57914) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2I74-0003a7-WA; Thu, 13 Feb 2020 12:17:19 -0500 Received: from [192.168.12.213] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1j2I6l-0007cD-1X; Thu, 13 Feb 2020 18:16:59 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1j2I6c-00049S-W0; Thu, 13 Feb 2020 18:16:50 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From; bh=VW0xZuhRsG4PibYDsRGfffGxJBPLKMsp0cRTwwaNPlc=; b=DbqPIwZ6+mnI0EUzT7vAfQprDcd3fi1e4DMXy1HQGTP0IvJBjOGQUVnuICZBh+jvExf6CdBPaSUjQ5+Mh3PUK9MqLUFPqBMc4gm+46YqUGXjL2iWEgvUaX5yyggT/VBIavf4YiFgB8kuwqHkrirrfbTYCLZwclVja6PxxK4JTYsimn1qN2prKT2x9+aOVgrvKfGnXaQbxc5PIzpG4clZLWqCOdlhNIXSjabCiuMjl2n6epu6PjHveYUkFLhih9ddCwts405mZ8Iq2doziuM5J6thK7gKjv8YbPHmJckZyediHQT6vp4mNS06SVzHjio5TEjHSR7qP26Gh4V6R43+PQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH] qcow2: Fix alignment checks in encrypted images Date: Thu, 13 Feb 2020 18:16:46 +0100 Message-Id: <20200213171646.15876-1-berto@igalia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 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 , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" I/O requests to encrypted media should be aligned to the sector size used by the underlying encryption method, not to BDRV_SECTOR_SIZE. Fortunately this doesn't break anything at the moment because both existing QCRYPTO_BLOCK_*_SECTOR_SIZE have the same value as BDRV_SECTOR_SIZE. The checks in qcow2_co_preadv_encrypted() are also unnecessary because they are repeated immediately afterwards in qcow2_co_encdec(). Signed-off-by: Alberto Garcia Reviewed-by: Daniel P. Berrang=C3=A9 --- block/qcow2-threads.c | 12 ++++++++---- block/qcow2.c | 2 -- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c index 8f5a0d1ebe..77bb578cdf 100644 --- a/block/qcow2-threads.c +++ b/block/qcow2-threads.c @@ -246,12 +246,15 @@ qcow2_co_encdec(BlockDriverState *bs, uint64_t host_o= ffset, .len =3D len, .func =3D func, }; + uint64_t sector_size; =20 - assert(QEMU_IS_ALIGNED(guest_offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(host_offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(len, BDRV_SECTOR_SIZE)); assert(s->crypto); =20 + sector_size =3D qcrypto_block_get_sector_size(s->crypto); + assert(QEMU_IS_ALIGNED(guest_offset, sector_size)); + assert(QEMU_IS_ALIGNED(host_offset, sector_size)); + assert(QEMU_IS_ALIGNED(len, sector_size)); + return len =3D=3D 0 ? 0 : qcow2_co_process(bs, qcow2_encdec_pool_func,= &arg); } =20 @@ -270,7 +273,8 @@ qcow2_co_encdec(BlockDriverState *bs, uint64_t host_off= set, * will be written to the underlying storage device at * @host_offset * - * @len - length of the buffer (must be a BDRV_SECTOR_SIZE multiple) + * @len - length of the buffer (must be a multiple of the encryption + * sector size) * * Depending on the encryption method, @host_offset and/or @guest_offset * may be used for generating the initialization vector for diff --git a/block/qcow2.c b/block/qcow2.c index ef96606f8d..8dcee5efec 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2068,8 +2068,6 @@ qcow2_co_preadv_encrypted(BlockDriverState *bs, goto fail; } =20 - assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); - assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); if (qcow2_co_decrypt(bs, file_cluster_offset + offset_into_cluster(s, offs= et), offset, buf, bytes) < 0) --=20 2.20.1