From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kQoyQ-0005Jl-OH for mharc-grub-devel@gnu.org; Fri, 09 Oct 2020 05:46:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQoyO-0005Ir-EC for grub-devel@gnu.org; Fri, 09 Oct 2020 05:46:00 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:44097) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQoyM-0006HX-SX for grub-devel@gnu.org; Fri, 09 Oct 2020 05:46:00 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 6F6EB5C00FB; Fri, 9 Oct 2020 05:45:58 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 09 Oct 2020 05:45:58 -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=XT3Jr6UwS5nDlBj3oeRmm/nxw02 nyrlu6lrBUzubCcI=; b=FIArARxHgkzrcnEl9wAA5hHVN28J6W/Va+2j2erR3l9 q4ccBd3jcm4VXghg+d8I9DyF+bCE9tKBiunKCw4FC2K6nxSDJpQ+KS4qvW+aCJX0 IM+ysBlp8ba07LT7NZIHfEMCC8vqMR/4C0kwcxCQkKIi/X3fna90DqlbSgONlpKg J1XGqFocvvJ5pya2lGzMSeJwI/rQTJjmbNEBGbtjBXIH2wI6v1GkNW3LJ2LliUrY hFY5lfUDLgCLWy4zZ2z4TRspCUE7auPVsw6Izj+RnLH6mWXh4v2FznSxA+7Qo6Zm okCFIJZZsDq5AsY05X6lF4bUlpcwRxCWt5auUfcJ/qQ== 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=XT3Jr6 UwS5nDlBj3oeRmm/nxw02nyrlu6lrBUzubCcI=; b=JFfFEhbGEDJrriumew6doG SnX0M9MDKz2y5jBAiSpWP/K4Ec2N95F9fLvZ3qAJLL7+nn3fTtFxrXg1oL0PJGc5 OOPrwVshUzRtYDg2HjalIM3SFBexM8wqLcvNor+mzSttWZYunbGw90LJzVWPIvfO /cxF2LunCXl9t/ZUnEoV57vDyn52Erz1hu1d2vDMI5hJhONkSlI3lVCPBzF/H39M r2EkPrufBXGnmHEcMTGT+SJ1RE8ml7W5UphYXUOIpMvqRdZ/u1LqugwvvTSQ4t0g vqHCMsaeTSkb26Kt7rI8TLAF8f51Y7Mc3UcFQ8QsAiVZdi+Ax6/BtTBM8BWLaXxg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrhedugddvudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu kfhppeejkedrheegrdefvddrudefgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (dynamic-078-054-032-134.78.54.pool.telefonica.de [78.54.32.134]) by mail.messagingengine.com (Postfix) with ESMTPA id 6C03C3064674; Fri, 9 Oct 2020 05:45:57 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 53560761 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 9 Oct 2020 09:45:55 +0000 (UTC) Date: Fri, 9 Oct 2020 11:45:59 +0200 From: Patrick Steinhardt To: Glenn Washburn Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [PATCH v2 04/10] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Message-ID: <20201009094559.GC2088@tanuki> References: <3baffdd4f0abceb0cc513dbee0075617f342eadf.1601765266.git.development@efficientek.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="z4+8/lEcDcG5Ke9S" Content-Disposition: inline In-Reply-To: <3baffdd4f0abceb0cc513dbee0075617f342eadf.1601765266.git.development@efficientek.com> Received-SPF: pass client-ip=66.111.4.26; envelope-from=ps@pks.im; helo=out2-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 05:22:33 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, 09 Oct 2020 09:46:00 -0000 --z4+8/lEcDcG5Ke9S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Oct 03, 2020 at 05:55:28PM -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 sectors. We need to convert the sectors f= rom ^~~~~~~~~~~~~~~ Nit: there's a duplicate word here. Patrick > 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 > --- > 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 db251cce0..9f7d6e12b 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -424,7 +424,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 --z4+8/lEcDcG5Ke9S Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl+AMVYACgkQVbJhu7ck PpSlrQ//ZML+JgtCg3CRguIYRjrEk9ECK3DKZPzEgoS+/G4yW9Id/bHVG0IHrGDn hB7JqIzFmnXQjkVNI71acSIXFZEdD5WvDtazlB4OXtkZYG/spDLoTkF0lP0OytIW 1vYhsXgKQpcNRmYDFhpj0c4kV7D6jHgsiZienufxtw5jt56HGwL7G3XeEy7shXPN ru7Kkgov3NySUBzCRMXDdijJzUWIG34FqppcnYX6hKv+AR4FTpvM6JmdczARGbs5 wyJiIFg583d27ZqOhDYhxpmkG2fCJrjImtyPCdlxaA84Q8uHgs9m2oN/Vb73UlQX KAyMN27tEsXeHUfzxmRjCc3gDfB9ztH9E1GCRrdWmE7MT67zmaPfPL+yDK9dix8a RaeP4/WL1YYqcaWfEoL6cKbzzmf5/8Os4VHI9g3STKZLAnMBLm61hrrWHFqh6/qp 5WV8Gy0XizU0CZrQYv105yfK/7O+2MDwTjVCQ8pgHz2t+eVlS67yIfTu9OFeMYt5 AlIf3X8l+ayA25WcQXs+duL2yZV3ocbJAs+Ehps2gy0aE1a/t73rGLhImhT3ZStv LXsn2r0u7mbzpnZyJWK0Th0iEGvVrvXcuX54tUdVlWvBzwKcJc32uXyJNtQ6Np1n RbvD0/yZ7IPdnXCiDm8/5vmt9+aI+JjjRy/tM0RVt5jBBkgm1e0= =3xek -----END PGP SIGNATURE----- --z4+8/lEcDcG5Ke9S--