Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1k1X36-0007bW-0X for mharc-grub-devel@gnu.org; Fri, 31 Jul 2020 11:34:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1X33-0007aP-P2 for grub-devel@gnu.org; Fri, 31 Jul 2020 11:34:17 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:60597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1X31-0008Uy-Bf for grub-devel@gnu.org; Fri, 31 Jul 2020 11:34:17 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id E58B3D71; Fri, 31 Jul 2020 11:34:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 31 Jul 2020 11:34:12 -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=uqCK+2tHUcUyz0vAQ50ugjsvL/0 VG1fqtacyr3OH4B8=; b=dcRObpL6eyHVuiih8RbXZnI4aNPJK/X3/y8bv5vvqdx lXYVSTs6+aDuS8CXdhtUAV5gs77KvJgsJiq0/7xYa9EisJji5HLjVFx+sToV11KY vsi9xc1tn5CiqCi1FUjlXPrwtyXveI31EOYbsdWVuJgPGy40IDayGiE9Q2tUmr82 Dz5Zu2g5X39AhsNA2JwQamaINXgwm1J2JrlMxUnLQYA/hck/PCnXIv4508LbiAUF aolDukFAcP6aBkPKIxhGnuUkgSuKGrGvPSF+gBSxAh4kZv8YdhWD598T0VuHcN51 GRyJA7cOoPHWE+cCMQXPG93FDz2wIhEo2w8hjdB9L3g== 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=uqCK+2 tHUcUyz0vAQ50ugjsvL/0VG1fqtacyr3OH4B8=; b=LQ+6lQca7r6cb7+E9uk4hX bktA6zA1rfUNkoInqtja/lKaBa4yOnlkd7cQ/ixqpmPQbrZiN3Ten/iOe1KzFCTC 7OAfJlaeQyWf3S5cTslRtB/Ac6oQI3Q8zElGP6T3AtV17Pmlt20Ib4pap+NJIJAo /6BXU7sOoQe4X411eOOU3XqdwvZ6f+qIM6XtEhpOgTYJI0a6LFj6X27WMe/7E2fY 4oWTfvnwlnULHk/PNfY/hFHIDxto+WS3SvIyhu0rZGNL8nDrVssbm5JglCq3AQg8 ggi13dEOxBvjdIrTF39gyeV7OQQwhKkOTEE+AfGVE23EjLdf2xR4A0rbRfj3Oqtg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrieekgdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu kfhppeejjedrudekfedrgedurddtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (x4db72900.dyn.telefonica.de [77.183.41.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 9CB103280063; Fri, 31 Jul 2020 11:34:10 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id b865af06 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 31 Jul 2020 15:34:06 +0000 (UTC) Date: Fri, 31 Jul 2020 17:34:18 +0200 From: Patrick Steinhardt To: Glenn Washburn Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [CRYPTO-LUKS v1 08/19] cryptodisk, luks: Allow special processing for comparing UUIDs. Message-ID: <20200731153418.GA11731@tanuki.pks.im> References: <0bb8c2733f0ea3911537bc559bc044ac371d0fb8.1596196383.git.development@efficientek.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline In-Reply-To: <0bb8c2733f0ea3911537bc559bc044ac371d0fb8.1596196383.git.development@efficientek.com> 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/07/31 11:34:12 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: Fri, 31 Jul 2020 15:34:18 -0000 --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 31, 2020 at 07:01:49AM -0500, Glenn Washburn wrote: > Create grub_uuidcasecmp to compare UUIDs in a case-insensitive manner and > that ignores '-' characters. This is backwards compatible with the old LU= KS1 > code that stored and compared against UUIDs without dashes. However, the = new > LUKS2 code stores and compares UUIDs that contain dashes. Really, the UUID > comparison shouldn't care about the dashes, as this change implements. Now > your old scripts will continue to work with UUIDs without dashes, but you > may choose to use UUIDs with dashes now too for both LUKS1 and LUKS2. >=20 > Signed-off-by: Glenn Washburn > --- > grub-core/disk/cryptodisk.c | 4 ++-- > grub-core/disk/luks.c | 20 ++++---------------- > grub-core/disk/luks2.c | 2 +- > include/grub/misc.h | 21 +++++++++++++++++++++ > 4 files changed, 28 insertions(+), 19 deletions(-) >=20 > diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c > index 847337072..e7a4b8082 100644 > --- a/grub-core/disk/cryptodisk.c > +++ b/grub-core/disk/cryptodisk.c > @@ -660,7 +660,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t d= isk) > if (grub_memcmp (name, "cryptouuid/", sizeof ("cryptouuid/") - 1) =3D= =3D 0) > { > for (dev =3D cryptodisk_list; dev !=3D NULL; dev =3D dev->next) > - if (grub_strcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) =3D= =3D 0) > + if (grub_uuidcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) =3D= =3D 0) > break; > } > else > @@ -897,7 +897,7 @@ grub_cryptodisk_get_by_uuid (const char *uuid) > { > grub_cryptodisk_t dev; > for (dev =3D cryptodisk_list; dev !=3D NULL; dev =3D dev->next) > - if (grub_strcasecmp (dev->uuid, uuid) =3D=3D 0) > + if (grub_uuidcasecmp (dev->uuid, uuid) =3D=3D 0) > return dev; > return NULL; > } > diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c > index 6ae162601..ea54a9d10 100644 > --- a/grub-core/disk/luks.c > +++ b/grub-core/disk/luks.c > @@ -69,10 +69,7 @@ configure_ciphers (grub_disk_t disk, const char *check= _uuid, > int check_boot) > { > grub_cryptodisk_t newdev; > - const char *iptr; > struct grub_luks_phdr header; > - char *optr; > - char uuid[sizeof (header.uuid) + 1]; > char ciphername[sizeof (header.cipherName) + 1]; > char ciphermode[sizeof (header.cipherMode) + 1]; > char hashspec[sizeof (header.hashSpec) + 1]; > @@ -95,18 +92,9 @@ configure_ciphers (grub_disk_t disk, const char *check= _uuid, > || grub_be_to_cpu16 (header.version) !=3D 1) > return NULL; > =20 > - optr =3D uuid; > - for (iptr =3D header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid= )]; > - iptr++) > + if (check_uuid && grub_uuidcasecmp (check_uuid, header.uuid) !=3D 0) I don't think the header's UUID is NUL-terminated. So if `strlen(check_uuid) > sizeof(header.uuid)`, we'll overflow the header. We should probably add a size parameter to `grub_uuidcasecmp` to fix this. > { > - if (*iptr !=3D '-') > - *optr++ =3D *iptr; > - } > - *optr =3D 0; > - > - if (check_uuid && grub_strcasecmp (check_uuid, uuid) !=3D 0) > - { > - grub_dprintf ("luks", "%s !=3D %s\n", uuid, check_uuid); > + grub_dprintf ("luks", "%s !=3D %s\n", header.uuid, check_uuid); > return NULL; > } > =20 > @@ -125,7 +113,7 @@ configure_ciphers (grub_disk_t disk, const char *chec= k_uuid, > newdev->source_disk =3D NULL; > newdev->log_sector_size =3D 9; > newdev->total_length =3D grub_disk_get_size (disk) - newdev->offset; > - grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); > + grub_memcpy (newdev->uuid, header.uuid, sizeof (newdev->uuid)); > newdev->modname =3D "luks"; > =20 > /* Configure the hash used for the AF splitter and HMAC. */ > @@ -145,7 +133,7 @@ configure_ciphers (grub_disk_t disk, const char *chec= k_uuid, > return NULL; > } > =20 > - COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >=3D sizeof (uuid)); > + COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >=3D sizeof (header.uuid)); > return newdev; > } > =20 > diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c > index 41329f745..7f5deb469 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -356,7 +356,7 @@ luks2_scan (grub_disk_t disk, const char *check_uuid,= int check_boot) > return NULL; > } > =20 > - if (check_uuid && grub_strcasecmp (check_uuid, header.uuid) !=3D 0) > + if (check_uuid && grub_uuidcasecmp (check_uuid, header.uuid) !=3D 0) > return NULL; Same over here. Patrick --VbJkn9YxBvnuCH5J Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl8kOfkACgkQVbJhu7ck PpRvKQ/5Ac/ROSfKm/JK/S75llO7WFN0qNsK18dyJq+WStPTSIlEScTjDw+cKa3Q ISfSZOLCxB+i5ppE7IFRQ3k+pX/d+k9akfgtdHrcaYZjx3GXfzw6Tl5n2cLx+kcO V365CZusvQRhIkEmX8b2yC+DTR1OX+fXhg3QjkyZQBmqDf9Z2YYcPDvBcgziyAdU nC0bxZnQ5eEb2yHc53zChL8PVbr8SRKnDke2WhdeiUQ8sjKqHIIRE6Waiu8KXITH EFBxgmgdLVtKC7VAw0eEBhrFa6jFNoRM8Gm3pjo9KaN8rNgahM2MYF6Y+aBy2Hd+ P38hVOvtRSZ3IWMOYzBYM1iN/D4gF8rnMgTfCgk5CV/k+6iUlimlikOL1rWQkWGt iZ2yuL/F3+bHP+gG77oDNWtGlfWB9DbP2l5Ck0j5yyMCrA1WpWU/mh7fT6k5qVUz 3p2XMdYX/t+eNOBnc6Ojq4OoQeLCvSHRXw3/HYYjs853v44mYgO2FYev8F8oDHdR 4jHy3i9yQtycoudvfvJBuyRR91S+2Jh4xwPqLgFhGOGjL5eeJJ0cfHYne4h/dfoW jzzs8PpItVubd+6QDjN6LsvTz/VCOGfdMH1+pPCs7fnfDDWE0wSi+bXR/qYeXJvY 1YeVmrNwnYsBFHQmVVw2UEnOADypd3NKpnzscVRz8XIzwpTwVeU= =A3av -----END PGP SIGNATURE----- --VbJkn9YxBvnuCH5J--