From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1k1AMn-0007jb-Lv for mharc-grub-devel@gnu.org; Thu, 30 Jul 2020 11:21:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AMm-0007jK-K0 for grub-devel@gnu.org; Thu, 30 Jul 2020 11:21:08 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:37019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1AMk-0007kM-M9 for grub-devel@gnu.org; Thu, 30 Jul 2020 11:21:08 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 89B53D60; Thu, 30 Jul 2020 11:21:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 30 Jul 2020 11:21:04 -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=wxe8yb6C+eSkiLOUwymGPtpGAt+ YtDDSngdXpgsU8DE=; b=u8xUxbsIHjgyMD3mbw7Kk/eldI+nM9lcp0e3BQi4uAM 4X/Ec0QAS/oatpErEuQlq/Kig3p4sds0gx2x+l/d401Zuj2piyHHBRzrE0bHjVej Dsmu0dbZZGlv6V9mq9VH8IgUwfrpQSU5GmRROTShKockla4pkA7LSVjHmdSiUWuN uu24vDd7r+ujuURtH5LAY3dB92aT9MFiHSMjn18a+N4EkfF9neNIWtqY59hkkhZ2 TLzvVKNmm5lKFXcckWJLJggBuysX8yNuiboNXHKA9HgDjI9/aD35psMvGGwFgRqK gP2xrMJ3zP0oDwyQP6J6VVmoANyf7gnBVfrkmrBpeMg== 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=wxe8yb 6C+eSkiLOUwymGPtpGAt+YtDDSngdXpgsU8DE=; b=rHhVZXGazhkNSI4BGg7hn7 ZK2D9hc/1Hx3u02jWbue8WvPxbQbPLsIzYWgnAmF/q0eHvmMmw+vsrIIEKofmAaS bAJe19oloKmgRAJndjwuG+E80B7ScfvsgOfM/LD15l3vupXaLbNR+qdSYRQli/Sy XtrBoGB8MK4dkvIZ6hKfnY5m4VEzY5jdcdAqCQNVJ3MTRVyY4NkhNPs8CjOW/dUB hgeH2v4ghJlIN166NvTpYmfg0iicY++XqDtr9xzr1JWFYUxK6eZEOD06mmbMDFYS xC00lWf8CUw+xiCBVz4zOwwcO/qVwRCOnfG0mR+n4xqixiiDLt6Nr0s1KV2ADlhQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrieeigdeklecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu kfhppeekledrudegrdeffedrtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x590e2100.dyn.telefonica.de [89.14.33.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 4A07B30600DC; Thu, 30 Jul 2020 11:21:03 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id b7c91b66 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 30 Jul 2020 15:21:00 +0000 (UTC) Date: Thu, 30 Jul 2020 17:21:16 +0200 From: Patrick Steinhardt To: development@efficientek.com Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [PATCH 06/17] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors. Message-ID: <20200730152116.GB39309@tanuki.pks.im> References: <1435ab49fdbac61ad4c189982724f8ef25c533a2.1596056714.git.development@efficientek.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="EuxKj2iCbKjpUGkD" Content-Disposition: inline In-Reply-To: <1435ab49fdbac61ad4c189982724f8ef25c533a2.1596056714.git.development@efficientek.com> 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/07/30 11:14:46 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.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thu, 30 Jul 2020 15:21:08 -0000 --EuxKj2iCbKjpUGkD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 29, 2020 at 04:50:11PM -0500, development@efficientek.com wrote: > From: Glenn Washburn >=20 > 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 f= rom > 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 > Signed-off-by: Glenn Washburn > --- > 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 e3ff7c83d..632309e3c 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -416,7 +416,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; > @@ -602,9 +602,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))=20 > + - crypt->offset; Oops, thanks for catching this. Could you maybe add a comment wrt to the magic going on with `(crypt->log_sector_size - disk->log_sector_size)`? I didn't think too hard about it and am in a hurry, but the conversion isn't that obvious to me. > 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.25.1 >=20 --EuxKj2iCbKjpUGkD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl8i5WsACgkQVbJhu7ck PpS0Ig//bj8E6bXD3CEDqHP1pIKjdwM1YqgD9fy/CDLHZZOse1Zhx6UMrKihY++Q TEkuGK8LlLPop8jIyM2pp8TOs/8e6fxvR45MHwJDM630qVbTqqXCQ1Ofmdlzn8tA LMEomaZeZydnPthIuU8HhZjy2EsaFP/ssOfoXks7edALKq97Nc4PbYulYj5y1NWR j3LIbQQ5g0zYnuiejLDqu8xisUsDvt5AsEyHme9EHM42hVhfBZmzfGF39yFbfcRq MCgWpUGJ89t8RPp8oEpA1e4bWVl4rsQCziwKDbC+0ZdGNVnuhWxLAZzIRRTD66iX 4qbQ7ztX9WDwF9Vj/mo6LZTrGPve2hLwedjRTyZY2AuavfR5G9I0Px63Vy8AYoZR Rr51TpeUSgGM9ryqRbdWwkj2LRBW3yq1trk7j3pi37KgVgAyn8Y3pPk47uEVRfaA UqyyKsrnpiB86DAbOPnH6h0mJwvGpUG2AG6VEn9WPAJKQ8xoSN0uol7CCM+luSRT 4H27sQNw8XPCGbbCVDNoYQesTtm4rOqyqb2j28+TLLwWdLythPUttr91KCiqjaZN Td8bVVFsB0C/F5jJk6IQzwHke+ojW3IdhPJleKyImqJwRcoINNZPaf9vgbnlfvcU QQNaEDnTJBTWdWHCnaBpFJO3+Q2EpS/ICwAuuhPlVIEFMYdc5BQ= =s0Zz -----END PGP SIGNATURE----- --EuxKj2iCbKjpUGkD--