From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1k9nnp-00026l-F2 for mharc-grub-devel@gnu.org; Sun, 23 Aug 2020 07:04:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9nnn-00026d-U1 for grub-devel@gnu.org; Sun, 23 Aug 2020 07:04:43 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:56761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9nmq-0000F1-9k for grub-devel@gnu.org; Sun, 23 Aug 2020 07:04:43 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id D32F1580310; Sun, 23 Aug 2020 07:03:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 23 Aug 2020 07:03: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=kz/0Q1WI7f/dWsAzIdEHH+8yA1z 52o13cNrtXOEmvpI=; b=SMBdS4gjCqbM04VJYm3oNVCbhex2dGC4vAla+FkD1tm jFydTYasPV/0CE33vgFinOOkxdAEVDHW0PWS0O3BgBmBA9NLUSN1JXJW3+0AfLC1 qShI0/jYJvO7VWjy/nPjgFSnjoOx9Jpe9p/NAh+2i3/8FZ3gunuINshPBGbgDmuR slK9oBpRPnDj29PlaTQ4Z76QwN6U2U1UhoLr6B9QN4OXPekgPaGp40ayHDOVKccH AV6ohGuUZ3SIYkgz3Nap6c67xoAKhuvOIT94Rk1KDNa2LRKZQI44M8d3cCuplc07 mVD8Oxr1Fd/VCstOctZuA1h2KMyhBGMQUrBAZ8K0pdQ== 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=kz/0Q1 WI7f/dWsAzIdEHH+8yA1z52o13cNrtXOEmvpI=; b=am/iD/I0JDr75zSxDtfp4f zolDWjRQttB/GnXze9i4JYZp5B+BuX2b1KmItXuxtOQEFMwo5c/Mr/vozINaUukn 8KE2QGjqP2gf99mDUulgknqq0B6rKkqJ1pLbxz5fOCRLG9Xe/oGyDAlugTU64b9o 8rE2uOyPfyo0EE5/I/pGRvVh183xeXJ/Xau3jErW8KSSVArR2ePXVrN7hHN5M169 GzjF3x8G24OWa9dXv9fPfstM1ZQyVA2L1rxDEfCNceonI92f3yCPtlMR2zAOTXoe flKCrhX03A2zj81Hd2fql1Fou1H9tDJj90yu1yhTXbvByvgNpmU76Fm7bor6Bqvw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudduiedgfeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehgefhtdefueffheekgfffudelffejtdfhvdejkedthfehvdelgfetgfdvtedthfen ucfkphepjeejrddukeefrdehkedrudelheenucevlhhushhtvghrufhiiigvpeefnecurf grrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x4db73ac3.dyn.telefonica.de [77.183.58.195]) by mail.messagingengine.com (Postfix) with ESMTPA id 08C73328005A; Sun, 23 Aug 2020 07:03:32 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 12c045aa (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 23 Aug 2020 11:03:31 +0000 (UTC) Date: Sun, 23 Aug 2020 13:03:34 +0200 From: Patrick Steinhardt To: grub-devel@gnu.org Cc: Denis 'GNUtoo' Carikli , Glenn Washburn , Daniel Kiper Subject: [PATCH 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="ibTvN161/egqYuK8" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=66.111.4.224; envelope-from=ps@pks.im; helo=new2-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 06:59:58 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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, 23 Aug 2020 11:04:44 -0000 --ibTvN161/egqYuK8 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 200f81d3a..fa4b62825 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_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 --ibTvN161/egqYuK8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl9CTQUACgkQVbJhu7ck PpRXQxAAhigCgxGTUxxHi3AUrM5oKcDR5681DfIEZrlDxZgMrqLKtf+NQQHaKJFu TTLxtxmttLy48B76dmyHvJbEXevQUhrKlgQ++p4MiKi5fbtbrR0WrZhXMP1td46q PUt+I3mNgbIlXgDfSGWvnBB+uvC9ZUKiG3xHCxRvLOnL8Nkfd5gHL7c8soI15UQV lIbr48an7t3/fuMIpXKMKX0GxLd6K60dng9SrKCeMV5lbtoBszq97LfC8N59rwxB m7BB7ha1PxYMmw62k2roWECYjWxsNo1HRI/C1UoeJj/mHi+y3VVhNS31zse4CELW e4btkZqmjZdj8zN4XYM1yIyh5bWxmBLFvyLZb0NuXDtDeUDUSFFSPU2gFPEdEbSA 8iUUJA7bgejpUUX00qh/cGBvYbQ8/OH2J767Z/NXPXTAjHbI1xRaEQadM6NDgIQG IiyIBd6p6hdOfxewiVyyLkl8IrBFlUd9iwo154MHmQzbt2qQy1ZsefAy7K/Ix4ZU S3BCspCT3KILwzX19E2PhZC/TlmvBNLS1R7KNzEBi3RP8WFVcx9CL84hNBq5FEU9 Mk1XOTfgvWbwrsXHSl4/SvpN+nstbNitWMVh/Lfj5cpp4f0h2lxDOlt/NQFo6EFK 7Hq/6Hrle3ieGHudACvQq9tbx/Zl3KoS7H4cXycrzQ6XorLOFz4= =i3/x -----END PGP SIGNATURE----- --ibTvN161/egqYuK8--