From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kFJ3i-0003VQ-7r for mharc-grub-devel@gnu.org; Mon, 07 Sep 2020 11:27:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFJ3g-0003Rd-JS for grub-devel@gnu.org; Mon, 07 Sep 2020 11:27:52 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:39983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFJ3e-0007Dz-Nr for grub-devel@gnu.org; Mon, 07 Sep 2020 11:27:52 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 62912BF9; Mon, 7 Sep 2020 11:27:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 07 Sep 2020 11:27:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=33wujvEVKCLjTjjhGHA/j9yWkwp DeJcDQpdNuWRQd0w=; b=l1h17NLiUvyoXvSFjmzhxpTo95heSj7vYoUduhGSX3z 1uMW1AdwHpHN+8188J49Px61Ej9BUytzlr/msexSTXJuFQODHDTAKTHXS+xAf1FJ FMW8NfNl7MfnQdq36jbM+occHn5lQf05Yv4jQj249fTXWRamvEgFjuGaFBKPIHJs otSnZi12va/USy+0aOD/u6FlByPpnrnW1x1CIhNzpU26Uq86QRe09UEeqrYAqogs 7AQPjMueivLB8/Csh0U8kaoWCb1Kt/wDXP6kmFEoxhiZwL01IVAphuJxY1hGfY+y nKDD1W6vZHplkaFIpXYqhtU1FN0AiPZLaXMFqqfyGVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=33wujv EVKCLjTjjhGHA/j9yWkwpDeJcDQpdNuWRQd0w=; b=VsQx3wLpl0CgmUUSewW1kV 8/a899XDzRO6ILvY0vGy1BXhFfhqTiQR37Fjpt2F9tblqU/0JIeFZBPqOwJx65eq OTfhJMCpW4EJOs2IzSthtFxSX2Ysw1Y65B6eFyZzUHh+E14Rz88126jRBXi73nMD ANx5b/IPRR8lBK2s5LzFI3mMMhAvUEUYiPKs+//GRRpM+wgodNCCJzqRgm50bSXN qBBYKGdR5+UYwNRuvB8ORa1VQQcHvwANjrCaQESrckwYHuDGEqbD3LqwxI8AOgLJ HMESLsJQGK02DMvSboEWDrO6Ic126nuomHauAnq+vrNTAIRw4lRfwTwTZH7C1FHA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudehtddgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucfkphepkeelrddugedrfeekrddufeegnecuvehluhhsthgvrhfuihiivgepgeenucfrrg hrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (x590e2686.dyn.telefonica.de [89.14.38.134]) by mail.messagingengine.com (Postfix) with ESMTPA id 346123280063; Mon, 7 Sep 2020 11:27:48 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 3e513dea (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 7 Sep 2020 15:27:47 +0000 (UTC) Date: Mon, 7 Sep 2020 17:27:46 +0200 From: Patrick Steinhardt To: grub-devel@gnu.org Cc: Denis GNUtoo Carikli , Glenn Washburn , Daniel Kiper Subject: [PATCH v3 4/9] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PEIAKu/WMn1b1Hv9" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=64.147.123.25; envelope-from=ps@pks.im; helo=wout2-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/07 11:26:12 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Sep 2020 15:27:52 -0000 --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable =46rom: Glenn Washburn The total_length field is named confusingly because length usually refers to bytes, whereas in this case its really the total number of sectors on the device. Also counter-intuitively, grub_disk_get_size returns the total number of device native sectors sectors. We need to convert the sectors from the size of the underlying device to the cryptodisk sector size. And segment.size is in bytes which need to be converted to cryptodisk sectors. Signed-off-by: Glenn Washburn Reviewed-by: Patrick Steinhardt --- grub-core/disk/luks2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index c4c6ac90c..5f15a4d2c 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -417,7 +417,7 @@ luks2_decrypt_key (grub_uint8_t *out_key, grub_uint8_t salt[GRUB_CRYPTODISK_MAX_KEYLEN]; grub_uint8_t *split_key =3D NULL; grub_size_t saltlen =3D sizeof (salt); - char cipher[32], *p;; + char cipher[32], *p; const gcry_md_spec_t *hash; gcry_err_code_t gcry_ret; grub_err_t ret; @@ -603,9 +603,10 @@ luks2_recover_key (grub_disk_t disk, crypt->log_sector_size =3D sizeof (unsigned int) * 8 - __builtin_clz ((unsigned int) segment.sector_size) - 1; if (grub_strcmp (segment.size, "dynamic") =3D=3D 0) - crypt->total_length =3D grub_disk_get_size (disk) - crypt->offset; + crypt->total_length =3D (grub_disk_get_size (disk) >> (crypt->log_sector_= size - disk->log_sector_size)) + - crypt->offset; else - crypt->total_length =3D grub_strtoull (segment.size, NULL, 10); + crypt->total_length =3D grub_strtoull (segment.size, NULL, 10) >> crypt->= log_sector_size; =20 ret =3D luks2_decrypt_key (candidate_key, disk, crypt, &keyslot, (const grub_uint8_t *) passphrase, grub_strlen (passphrase)); --=20 2.28.0 --PEIAKu/WMn1b1Hv9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl9WUXEACgkQVbJhu7ck PpRHrA//RiyRlQs8Whaupc2HMY87d4/hES2cQs7c//lQJ7fv8YXLvz6Ot7Ms7b9Y 9Gzhi2XPPbaqZkTCRJtK9o62D3BFyDK+G9NqqlHVTR/8zh8VoSH0SMi4DpsQQzpk wNxI/eKip+dZRcUxtu0tbWOHJik44lhT8A/erclhxwCaOaLlBgLJFd3j3ikhHmwH lz6uofwgNqjpRUz5xNd0b5JPZWmveSOV3ytvXsdi9MESCnDcvvk7p7sHHnCa6v7m 2fqztpE98FU6RxVjPET77Pxb230uMoB+CcSn5bd0fCe7hTpfT1YpW8VJAp2cgKLt rwKRMmv5DYotpiE+Ti2P1kX1fK5/rVJnVKDg02peBDMJ7v9H64a/mKgEgjgYLRvs 3VRn9Yy9F4qX2+tB8yrbdSbQ8ekspU1sy8qaJ4mj5QP0ebSmz+IChEebqd96IE8D u2cXmewPquKFuE6lBXosXDaouvjubsFTzSc2Lf+0dgLD1B9ggq2Qf+LJU5+qKkY1 99E2FuY37mp4Z0RGzef5LCQDshiz0frkX4xJNGJjJNQw231ZFlPh6byIgNwiaZhP sa9Ye/f2xVwoALzYw7pPM4gArU4N3T8N7qQcW1x2ulnzFs7mphevCKXQ/zAWSGRn iGnW+AWBA7Y6Svz/8XD5sxDsDZ60Hs6tp5EDEH4R2LOhDRkXyHY= =D3ba -----END PGP SIGNATURE----- --PEIAKu/WMn1b1Hv9--