From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1o3fzb-0002Pd-QI for mharc-grub-devel@gnu.org; Tue, 21 Jun 2022 11:40:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3fzV-0002OD-V0 for grub-devel@gnu.org; Tue, 21 Jun 2022 11:40:35 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:51029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3fzK-0000MW-63 for grub-devel@gnu.org; Tue, 21 Jun 2022 11:40:33 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 36D353200936; Tue, 21 Jun 2022 11:40:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 21 Jun 2022 11:40:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1655826016; x=1655912416; bh=DIfcvXMQVF BACh4o0z41DyJkiDNh2XCtgJ2MqBtzD3c=; b=eA3l/y8UAO6GfJ6uB+zVqwn0ev co+xdMcjGIwQJ/uh1thFswG3norvFRZw1OFH/bo7otcQbBYhJUgWvDgmQm9o2QVs gSkD2UHmEl2CNCVwbfvufwlHEKMBYcduz67HpBXFYDSZcXZd//WcG7Y1EED8OgZl wHVw6U3zZYtRLtYSV/JD5yI63N2oeTgHuBm+rwKLFCk9rHOyCr5gNCEDoSJs0N76 Upagzh9xTw+CkJ27Ze5q6Bc+PjrmASDhoHe8MXwjBtGyIBx58VsM1amM8VYTigw5 hM53jFVP4RuCf5hRD7NJzDocNHammxB4zlWEUqdDO5K6Dw18Qo7JfCYSXNGA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1655826016; x=1655912416; bh=DIfcvXMQVFBACh4o0z41DyJkiDNh 2XCtgJ2MqBtzD3c=; b=qfP15o/2P2265loIAsd77oL5QoDw5ksoxkQ7hzhZI1tJ lbY6znSp72h0MJTRA6DuBALLQH4ebEgQ5W5dI2O3qapAxJwjuA4k9oUmI9+Lk2ib NEZahQWOjSIujinToBOY15TvHBxlZkGR0xPa9N9bcHybQEodhd2zrFwQY9/UGi0+ IwrK48pvVN5fXOFUyCr6jXAKimIB5MCDf9o1k5GctxLePb3tV+2tMVxle+MDEbux Bf9O98Qcb0B+sW6B/0wWGuAXLqXj1cQ4GGbzw/P7kf/2Ordk+3TIDXEAkNM5a00u /qOTm11S+/5QC024CPJl6qsl4CoRbLWnaIZHpROCGw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudeffedgleduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtroertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepheefhfeutdevtdefieetueeggfefleegleevheffueekleefhfeikeetveduhfff necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Jun 2022 11:40:14 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id eec2ad64 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 21 Jun 2022 15:40:12 +0000 (UTC) Date: Tue, 21 Jun 2022 17:40:40 +0200 From: Patrick Steinhardt To: Fabian Vogt Cc: grub-devel@gnu.org, Josselin Poiret , Michael Chang , Pierre-Louis Bonicoli , aplanas@suse.de, Glenn Washburn Subject: Re: [PATCH v3] disk/cryptodisk: When cheatmounting, use the sector info of the cheat device Message-ID: References: <8075647.T7Z3S40VBb@linux-e202.suse.de> <20220613211942.76d843f7@crass-HP-ZBook-15-G2> <2848907.e9J7NaK4W3@linux-e202.suse.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="NBWkrSMTwb24rpls" Content-Disposition: inline In-Reply-To: <2848907.e9J7NaK4W3@linux-e202.suse.de> Received-SPF: pass client-ip=64.147.123.24; envelope-from=ps@pks.im; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2022 15:40:38 -0000 --NBWkrSMTwb24rpls Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 14, 2022 at 03:55:21PM +0200, Fabian Vogt wrote: > When using grub-probe with cryptodisk, the mapped block device from the h= ost > is used directly instead of decrypting the source device in GRUB code. > In that case, the sector size and count of the host device needs to be us= ed. > This is especially important when using luks2, which does not assign > total_sectors and log_sector_size when scanning, but only later when the > segments in the JSON area are evaluated. With an unset log_sector_size, > grub_open_device complains. >=20 > This fixes grub-probe failing with > "error: sector sizes of 1 bytes aren't supported yet." >=20 > Signed-off-by: Fabian Vogt Reviewed-by: Patrick Steinhardt > --- > v2: Moved new code from grub_cryptodisk_cheat_mount to grub_cryptodisk_op= en, > which allowed to simplify the code a bit. Also improved error handlin= g. > v3: More liberal placement of variable declarations. >=20 > grub-core/disk/cryptodisk.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) >=20 > diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c > index c80cf9907..b3c76ef57 100644 > --- a/grub-core/disk/cryptodisk.c > +++ b/grub-core/disk/cryptodisk.c > @@ -709,16 +709,31 @@ grub_cryptodisk_open (const char *name, grub_disk_t= disk) > if (!dev) > return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); > =20 > - disk->log_sector_size =3D dev->log_sector_size; > - > #ifdef GRUB_UTIL > if (dev->cheat) > { > + grub_uint64_t cheat_dev_size; > + unsigned int cheat_log_sector_size; > + > if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd)) > dev->cheat_fd =3D grub_util_fd_open (dev->cheat, GRUB_UTIL_FD_O_RDONLY); > if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd)) > return grub_error (GRUB_ERR_IO, N_("cannot open `%s': %s"), > dev->cheat, grub_util_fd_strerror ()); > + > + /* Use the sector size and count of the cheat device */ > + cheat_dev_size =3D grub_util_get_fd_size (dev->cheat_fd, dev->chea= t, &cheat_log_sector_size); > + if (cheat_dev_size =3D=3D -1) > + { > + const char *errmsg =3D grub_util_fd_strerror (); > + grub_util_fd_close (dev->cheat_fd); > + dev->cheat_fd =3D GRUB_UTIL_FD_INVALID; > + return grub_error (GRUB_ERR_IO, N_("failed to query size of de= vice `%s': %s"), > + dev->cheat, errmsg); > + } > + > + dev->log_sector_size =3D cheat_log_sector_size; > + dev->total_sectors =3D cheat_dev_size >> cheat_log_sector_size; > } > #endif > =20 > @@ -732,6 +747,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t d= isk) > } > =20 > disk->data =3D dev; > + disk->log_sector_size =3D dev->log_sector_size; > disk->total_sectors =3D dev->total_sectors; > disk->max_agglomerate =3D GRUB_DISK_MAX_MAX_AGGLOMERATE; > disk->id =3D dev->id; > --=20 > 2.36.1 >=20 >=20 >=20 >=20 --NBWkrSMTwb24rpls Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAmKx5ncACgkQVbJhu7ck PpRq4hAAlU66lX+Ueak5qBwXkWwMzqKnuKJpwyrUn4n7K1kFz9lNCx3m97t3ij8J SRAQFaQOms72VYkncipicdDakYByEbMUYdvlK83z6KPDmEiBWcjfBXxd1UZ/aQ9T RjA0FlGpvWGn9JHD33jaw0AYz3o7FkaB/JGLJ/rRIvOnzdS9YEEXL3QPoD2JE04H V5XPdwoVs4ng471fpAMl6jygHqamZJ6yjtawmGc4gVisEUww59EfeqhHQwD2f5C2 DkC8qNYUJOTo8PDw9weO2swQYBULooO95U6Rk2Y816c3+fRRUcYpx/W4avrlHabP DKy6729ieU++yIraFa2hrFDtXLF2Urkj5xBlhUmR88kmASMRkvKz7kR/2x8qE2VO VX6hHrw7NO5G1xRZBYa/PTk9v+fImSukkTrYQxcGQhENti94rQuqobK/TM796+S1 X6BpbCQxE1FP4JgUjknhnqZPQ7T3cPUhl69OOYLBsxymczSTN3S84kpwPbSdnwlb Ew4CSnMTSaVKXaMx/Dj2/rAOvb1fasqJBcktla133bp44C7Q5HV2DvlWyi+PmHx8 BOFHlBqaToa/LW1YC5gdqth4574MVBvBDm+ELHfHOTUbaml+a602RLnPI6h66VdT ShAtvbrZ7ZO8Iy4y4qR7sxPdbD2Io4+Rsepza7PFQ19BtJvaM7s= =fDu5 -----END PGP SIGNATURE----- --NBWkrSMTwb24rpls--