From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kAqX5-0006o6-Tx for mharc-grub-devel@gnu.org; Wed, 26 Aug 2020 04:11:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kAqX4-0006jG-5H for grub-devel@gnu.org; Wed, 26 Aug 2020 04:11:46 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:47291) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kAqX2-0005OP-C7 for grub-devel@gnu.org; Wed, 26 Aug 2020 04:11:45 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id F159396B; Wed, 26 Aug 2020 04:11:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 26 Aug 2020 04:11:43 -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=fm1; bh=VIoYkwJGGmvRd50wNq65ap3LkXY Hj5T0aVZg7v57Zj0=; b=eUKBrT+E5FWNuoerBwVhcQmZ28gvjsCetyfYVqq79zx 51sbbh8qw5uutLazT9bOLoK6nsERxzEayot5uzl5J+zoht7KtqCt87qoaUFzhupw 5ibGLIdBRQYHWeFIvbNcdoGFrqGzQJBgD7zSJg3tvWury+8J3HnCpMa0/vUp6QZZ rx2VSnZQ4yiHMihx3WDa9DEIo9e4F209nTRmE2Qw+2ARiQ8eaRUlYG+MOgOmxOcq CJSXDV6jd9nEvZ2L34gEFrLPh5GRAjwdW+6ciSM/ipuFBOXNLpsa5z8m8vw4RA2B xWyiTHpdyv/+b1MvWIk3K02BAah17buipTJ+9yXexqQ== 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=VIoYkw JGGmvRd50wNq65ap3LkXYHj5T0aVZg7v57Zj0=; b=ReQazBrFuKLTcHn0tKelA+ EMlMgxt43Irpx+I6wyM6D8ksfil+vJ3oNXIxJh2QFjpEoZs9e6DtW8csSsY8cMwG eqsCNbiUV33I+PP/yv9UIYdekvwFBBXXjJjnuRf9mNuBm0zDXmKAlEbIDN4LzdEG I8d3xahlycQ9eXL3Y9cp8oEd4HnnycY57S5NpXpNXBBpq9kzMEZiGIRlSVEtLyd7 SFb812gv/Zjpib8QJEYPlmRx+kK6dlo77MuW89aU4Dgjw3IDEoZoqdEEgaKa7KTb kNbYJbeWUDCkj2RaZqOgkG6Mdte44Ab3lXcKJc9UaBJmQLSj0zOo6wZXKPB2gMOg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddvvddgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucfkphepkeelrdduvddrfeekrddvfeeinecuvehluhhsthgvrhfuihiivgepgeenucfrrg hrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (x590c26ec.dyn.telefonica.de [89.12.38.236]) by mail.messagingengine.com (Postfix) with ESMTPA id D1B453280059; Wed, 26 Aug 2020 04:11:41 -0400 (EDT) Received: from localhost (xps [10.192.0.12]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 49a9675a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 26 Aug 2020 08:11:40 +0000 (UTC) Date: Wed, 26 Aug 2020 10:13:39 +0200 From: Patrick Steinhardt To: grub-devel@gnu.org Cc: Denis GNUtoo Carikli , Glenn Washburn , Daniel Kiper Subject: [PATCH v2 4/9] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Message-ID: <150491a078422051f1f2eca920d9aa823e508ede.1598429170.git.ps@pks.im> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mYCpIKhGyMATD0i+" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=64.147.123.24; envelope-from=ps@pks.im; helo=wout1-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/26 03:16:08 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_H4=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: Wed, 26 Aug 2020 08:11:46 -0000 --mYCpIKhGyMATD0i+ 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 --- 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 --mYCpIKhGyMATD0i+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl9GGbIACgkQVbJhu7ck PpRpOw/+L7ZXTll/FKqZprZLAWmjUatSzwqDaoYM8haEY6cb8YYeEQAKa3XKFqSk pPjbV9ZNJATsFLMHMxH4ADMoITqxDNmP8P5ScXM0vXf8gSoxjcyS6BX2UiOEI8+5 rV1N0xo5bEFuvrINDFuPGf9uRAkaPVwsk9JHMtB9MZu/ENQNo2xDEhfsmnU6p07x 1HktzI/NsNqIQEiVUJ4p5rOZO2XoCGcvETTGs/V6qBVQof3s6jD67xMk73bKCznN g3N6ujV28LF73TA3kHoWNkRf7gI9oviZsf7V0egia6Csyv3s94nDsxlNWigNN2OQ 41hlaOZ7y/QDvMoLfiNTI8ylaYOTnzeSO8HGKHK6CMQFg2H/IOG29GVjJOJnvbAC YdDVjoHpb8M3dZAsggEYRAcKLSMw79fIcF7vi/fupl1csvXWyWg8YFiFSOMVfQAU YRy+Jn24qTUgMmm93NKAyCaBFmmUj+Qp/N2dLzLOH2hVRw5ojcXIadfFR033HhF0 xey5PotaioTffDfTwDGmcnCH2augDTHqtW0R8NEAXzPSyG74CdOwQMAsb1Oxw3yL bhwO6LSo7Lsv/o7GYsNj4l2sv6k8oI6aYKFuyxXHJIZ34OLMXkw3iSnsRyPxdruQ mkG9RECOsbxEn3TFB4vp3Zbe5Y51xxjv1HeUlGQnGixEtTj6Gd8= =7nKC -----END PGP SIGNATURE----- --mYCpIKhGyMATD0i+--