From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1keEpu-0005z6-7f for mharc-grub-devel@gnu.org; Sun, 15 Nov 2020 05:00:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keEpr-0005xG-09 for grub-devel@gnu.org; Sun, 15 Nov 2020 05:00:41 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:54751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keEpn-0007wZ-51 for grub-devel@gnu.org; Sun, 15 Nov 2020 05:00:38 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 818905C008E; Sun, 15 Nov 2020 05:00:32 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 15 Nov 2020 05:00:32 -0500 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=4h6yxfhUuoU9+r+EWJ1c1+OiIOX PQNLz/TO2aZTFyok=; b=wRlLmAFsPqQ7bzOOWJdzDy6pbq2MA465e2D7yLPkdC/ ETnzFGmD4gFDZLk20RMLYT9Lu4fjhrHkB03XPH9U+vb+AJCWICrMDiR+UphC60SX 9rBvZAZWBlz5EPgWN0wNCa48g5k39Hm9Q9diU0Mx6ghMRDCDb8TLGUcGcR8jhrY+ xHdnXenbR2I4IGPJz4ykgqWUuPRzpgwAmoUr2pgTqlORDSIyFbU8Z/WP57o+bkLi INHvmvH6LC9PMy4XgAKv8ZzXUIhkCzjlsp3oG5i08R9Ktz8SKQqI6a2LtfYp3wqv +/9IQsEwU4sGIH/SLGDhe2FoSZfFSAUwZ1pTSlaXkeQ== 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=fm1; bh=4h6yxf hUuoU9+r+EWJ1c1+OiIOXPQNLz/TO2aZTFyok=; b=l9P1TQkamisBlsZbkX665x hTT0mkMdeOckl2ofntg8ZV9kIZ/smbiPDKMvJM+KSo81guYA2tg3oi8ikdWuoFaz 9m+XYdAFnG8dNc2NenzFxNEOFFBeAKdahdvLwP8eGJAm95fOoKfwmGrb1IIQP+xl ORhDg8Q6+WsB21P3qY7zmTyeUZbY9y9bTuj9zUdsAKSdVZw+NDBmnPwg2hTek5z5 ww3QDZS0wucg9qLdbtbQ2eAc3dC9cpkFWtJEbNRcR63Ft4gAtfvFxSr0l0NDGAAe Qdfqc/Dcc6ZP6NPkUsfVZS9V2Oe4yJ5U+u73INQTqU2q8Sqj/uOGwbRG+0D8db0g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddvledguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucfkphepjeekrdehgedrvddurddvtdeinecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (dynamic-078-054-021-206.78.54.pool.telefonica.de [78.54.21.206]) by mail.messagingengine.com (Postfix) with ESMTPA id 0753A3280060; Sun, 15 Nov 2020 05:00:30 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 318c5c47 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 15 Nov 2020 10:00:28 +0000 (UTC) Date: Sun, 15 Nov 2020 11:00:27 +0100 From: Patrick Steinhardt To: Glenn Washburn Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [PATCH v4 12/15] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Message-ID: References: <1bc8c867c40610ac6e7c33622cc89396941da4b6.1604723348.git.development@efficientek.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hFqxu7Ye2QTmFNM6" Content-Disposition: inline In-Reply-To: <1bc8c867c40610ac6e7c33622cc89396941da4b6.1604723348.git.development@efficientek.com> Received-SPF: pass client-ip=66.111.4.27; envelope-from=ps@pks.im; helo=out3-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/15 04:37:28 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: Sun, 15 Nov 2020 10:00:41 -0000 --hFqxu7Ye2QTmFNM6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 06, 2020 at 10:44:32PM -0600, Glenn Washburn wrote: > 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. 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. >=20 > Also, removed an empty statement. >=20 > Signed-off-by: Glenn Washburn Reviewed-by: Patrick Steinhardt > --- > grub-core/disk/luks2.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) >=20 > diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c > index ca830d73b..355bb4aec 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -429,7 +429,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; > @@ -615,9 +615,10 @@ luks2_recover_key (grub_disk_t source, > 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_sectors =3D grub_disk_get_size (source) - crypt->offset_se= ctors; > + crypt->total_sectors =3D (grub_disk_get_size (source) >> (crypt->log_se= ctor_size - source->log_sector_size)) > + - crypt->offset_sectors; > else > - crypt->total_sectors =3D grub_strtoull (segment.size, NULL, 10); > + crypt->total_sectors =3D grub_strtoull (segment.size, NULL, 10) >> cryp= t->log_sector_size; > =20 > ret =3D luks2_decrypt_key (candidate_key, source, crypt, &keyslot, > (const grub_uint8_t *) passphrase, grub_strlen (passphrase)); > --=20 > 2.27.0 >=20 --hFqxu7Ye2QTmFNM6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl+w/DoACgkQVbJhu7ck PpTYWA/5AdnvofUAk2pa8w2EI9K5ANGoERBm+czHSp9bLju8ZA3Mwvye/U5/Zbir /dIX0y1r3dmpGJX4EvWOvz2sutUvz8WJYJqy8sUxU3PwXb9J0banseOr2RS2JccE nxMwQQ03FrbP/75JWCwVMLJBZp+OaWa0ujBYsVHlGdrtjRAuLPSRx37uDVdDcHsI z5yPjxovprF4mZiVvVd0jTg1f7SAsImeiaMHcZqaGjV2j70PHWTuHMgiRmCRv4t6 hIx5OoL6sq/E5ICN/Y44Of4tKX2bUlaF3EJOeQIJHwEVFkYaIvKk9z5dv/TVVkvN zFs2DCIJKOIKl9TxHuz5RQmv6JVUEI6KeHHpinu3ACAuiGHCpK66tbc1kWsbTp53 6K6xHE9At0YhljbRDQ/PHXhdrDop0wf8QvzUt2BjHBPzPUUlVBl3dRkLOUgKr21v EcMYRMUQGYo3MedRC/LhlPQ5XkvSD299AyJ6T62x1/pu+4LWG4XyUjaoMxkOQ7bn 5xAF5nDbn0r2GR6oX/yV6FgSMqr5h6Mw8equGUsB/be9g3ERhTpfDv3s49jSvfnL r8EzWrbCb3Y5enNrTsnfI7sGksShvKUq28bvDNBjuNCH8AjWpUOJboS6fI8+4sDc xU/YdnF7bVoV9oAddm6khJwVqVvun+NKXsOnvnSy+LxgCjyP0OU= =e0w5 -----END PGP SIGNATURE----- --hFqxu7Ye2QTmFNM6--