From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kW1Pp-0001VM-Hz for mharc-grub-devel@gnu.org; Fri, 23 Oct 2020 14:03:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW1Pn-0001SL-4s for grub-devel@gnu.org; Fri, 23 Oct 2020 14:03:47 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:39205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW1Pl-0005Mg-AZ for grub-devel@gnu.org; Fri, 23 Oct 2020 14:03:46 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id D80EB419; Fri, 23 Oct 2020 14:03:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 23 Oct 2020 14:03:44 -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=UbEs+2+lD35ASYYnzcjh7/0ApwG JHhlxqx4AENihfMc=; b=jwOvAoZLQ5iRPszax4F6aSAXTD6qVHFpi+RD6A6zfrF BvfDYcYJrzEiWAWzLzzZLbd3KvCSQ3ERJ20+x01jjucaDpm0Z8IwKqQvJ09DjMvS CBEp+ts2ER0S8DsuDQYtkPZO/mKzVJ+dg/wJ+dbpoQ0PfJyhVKPJk7DA4NjZlYYi NUaaZDeVQ7WITndRxU7F/0Hkx8/8qxFEVa5ovck+TL3um0Hsg2B4AOgaWE32GSUi upUagtT/u4pSxxqqO0isCYsf2ccr7xGaywBTCfPduIvOvmwuGLjn5AO+F0CKXelh rwrhLi5XrJsL4hM5tuabkxNoEQXoJsB/P2VPX6gBW6g== 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=UbEs+2 +lD35ASYYnzcjh7/0ApwGJHhlxqx4AENihfMc=; b=ahaDnImwKgaFWsklon8uhV D/Bumo4eXe2cXrOskKF6T6HyjSREWeAw7ea1xy/zSuhdr6IOOsdz2CtcaiX5vyq1 hCfo+pYAP3buqeLzhneRAYK5BnDwAZc3n7olTReLy1+TcvUFXCREsGRiYvYejolj OrjwRb9JcpZEO6ybnaCt7obVGv4p10TpmaviggLjvfRLhu3EiQ2Lc9ts6m0S2NgT jg96oR0wGo1gc6QyOjOfGXyjB7mvsFeCh+A4A8koHKD5WDcVq+iXrc6QmFqDzWhE sLcUjurFQMTczFZEWizJZp2ivNvBsM4XB/8m7yj6I23jeOkTCJ8zBL4s7MH28TJg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrkedtgdduvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucfkphepkeelrddugedrgeeirddvtddtnecuvehluhhsthgvrhfuihiivgepvdenucfrrg hrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (dynamic-089-014-046-200.89.14.pool.telefonica.de [89.14.46.200]) by mail.messagingengine.com (Postfix) with ESMTPA id 0DA0F3280060; Fri, 23 Oct 2020 14:03:41 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 7399db42 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 23 Oct 2020 18:03:41 +0000 (UTC) Date: Fri, 23 Oct 2020 20:03:47 +0200 From: Patrick Steinhardt To: Glenn Washburn Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [PATCH v3 04/10] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Message-ID: <20201023180347.GH810@tanuki> References: <20201009100122.GH2088@tanuki> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="dMyqICaxQaaUjrCL" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=64.147.123.20; envelope-from=ps@pks.im; helo=wout4-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 13:46:38 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: Fri, 23 Oct 2020 18:03:47 -0000 --dMyqICaxQaaUjrCL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 19, 2020 at 06:09:52PM -0500, 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 Patrick > --- > 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 4e1e47161..311d18684 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -425,7 +425,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; > @@ -611,9 +611,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_secto= r_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.27.0 >=20 --dMyqICaxQaaUjrCL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl+TGwIACgkQVbJhu7ck PpT6TQ//bdpX52OeotuTvOxtD+MKIwNNNkC26lSrJEjijXUUoaLFXeQZeBbrbw/z 0u0Knz2rHqCV4fyrY65xwBYvaBcCwB+lx6P8GPAEguAkYqkCmHv2iXJ9eGJp9FQW 26WNkUL4zcGY2ZQXtQAOWniT2zdtsbPsYr5AWaG2X2EDTo1xRV5lgl1U07yvDVnk g2mOz8I1ALPjl307EH/Ho85EeWKHo7OiHja2oJDJcI1OT6wIZ4RCNRL8nut2p7ou zTlCa3jaGlLzSnJwFYLeK1DsuMndYvJ1HxYh288t9gbcBgIC4jg0ECcB7X/WpAB2 KOw2wVgh1CUDDtb7YdyPr8qk4Ey900tIJrwtcqWdeTZcwb+L35kq+cI1RG35jJKO 15H50gMLlZlL+DXyBDKQWKdlQ+1XYbumc0vRxwoXQs6h/bfxXiQMlzzUT9SkmXFR HDjzZwl7zteqYcQUQHb8kUrAlKbEPyYn024g+XvPrfxO0NsbtpI+hfEVVc7bqaAS yNwikm8KHEvDN0OlULw2ecAppf8/d98NpYBfQSwuRFdw13bVEpmRRyOa+Ba/DRVu NF6jnSYW2aP50km2TZPzRjkT077PmvAreyjK7nQ7ronVKI0SOD9e3wTWmA110woN sca/CEVlmlrc3yn0UJtAYjNHnvCNlbx0YKwQ55q1Xxkiijj0kdk= =cdRS -----END PGP SIGNATURE----- --dMyqICaxQaaUjrCL--