Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1k1APe-0008S0-CK for mharc-grub-devel@gnu.org; Thu, 30 Jul 2020 11:24:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1APc-0008Og-FP for grub-devel@gnu.org; Thu, 30 Jul 2020 11:24:04 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:38601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1APa-0008DQ-8C for grub-devel@gnu.org; Thu, 30 Jul 2020 11:24:04 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id C99954C0; Thu, 30 Jul 2020 11:24:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 30 Jul 2020 11:24:01 -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=5ZwkeLacvo9zXpPZ/1Jp954Hqvp jfTwTCEbY/VdWDRw=; b=IGv961kkElJx1mm5ngJ/AZOqLisM7vj/tPXV+MBnKgV Ph+xc2sqt1eVvY2Q5GGMmNKD+rhObv8JFcZPxsD1AqoPCFVVDVoRBXwrM9UpwrVi YSZ4/QoB3dfZCD2ZhvVAP6MrlbyCPUUj3sTkNDYGMmu1KGslcSsf8mfF4CYC6+K9 YiTULaIfpj4x/3BYD/EjpD8oxmRKqDofzOEUEVT29bIreH390xF+QOu75AConOFw ROPm6iteEMTFX/IHmhdC3J8iaGKYuJI/qvkxASDWJOyh5jBYWLTHCX3GpPnGxHIP e/zV55fkGmBNl6AyhEi0VUArAnZSNVehreBxECBxeFg== 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=5ZwkeL acvo9zXpPZ/1Jp954HqvpjfTwTCEbY/VdWDRw=; b=e4qbAan+PiFu6BkhWMQ2jl EcVWA2+M5LAIsMfueQwDgX/WkfkhMZQoX0n3SKaiJsFxsnIw9S6qrAIgs9sofmV4 Fy+s8VeG7lemRNk3q+FZKySU6nYTUC0wdPDGVM5hXYwVfPwb/pQoeclJvFEEwtWj 9/uxWq6LKVWzTUMMwtmYn+XSkv7dIoiZjgDviiyQdSu6tE0Uot68cSWgXpxFj7i5 NAmzO/XdshE4gbNnntz4g935TjwWixJ8F/U64H+2+43H5yF5xJzoZiHByuvfkj9N KSDE1sTJ4tsDtI0BRfe4hprj5boP8SjjAOBa7gKGc3fOMgyDPQcynLb6wdqr6gmA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrieeigdeklecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epudegieeuffefgfegudeiueduhfdvffelvdfhkedvleetfeffudegveekieejieeinecu ffhomhgrihhnpehgnhhurdhorhhgnecukfhppeekledrudegrdeffedrtdenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm 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 93CDD3280069; Thu, 30 Jul 2020 11:23:59 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id df91e073 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 30 Jul 2020 15:23:56 +0000 (UTC) Date: Thu, 30 Jul 2020 17:24:12 +0200 From: Patrick Steinhardt To: development@efficientek.com Cc: grub-devel@gnu.org, Daniel Kiper Subject: Re: [PATCH 07/17] cryptodisk,luks: Allow special processing for comparing UUIDs. Message-ID: <20200730152412.GC39309@tanuki.pks.im> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="8NvZYKFJsRX2Djef" Content-Disposition: inline In-Reply-To: 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:24:04 -0000 --8NvZYKFJsRX2Djef Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 29, 2020 at 04:50:12PM -0500, development@efficientek.com wrote: > From: Glenn Washburn >=20 > 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. FYI, this is crossing with my own patchset to implement probing support for LUKS2 [1]. I do like that we start becoming agnostic of those dashes now, though, as it really is kind of annoying to handle as a user. 1: https://lists.gnu.org/archive/html/grub-devel/2020-05/msg00235.html >=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 f6b6302e1..f460ab838 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) > { > - 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 632309e3c..3c571b7fd 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; > =20 > cryptodisk =3D grub_zalloc (sizeof (*cryptodisk)); > diff --git a/include/grub/misc.h b/include/grub/misc.h > index b7ca6dd58..3f0f42c22 100644 > --- a/include/grub/misc.h > +++ b/include/grub/misc.h > @@ -243,6 +243,27 @@ grub_strncasecmp (const char *s1, const char *s2, gr= ub_size_t n) > - (int) grub_tolower ((grub_uint8_t) *s2); > } > =20 > +static inline int > +grub_uuidcasecmp (const char *uuid1, const char *uuid2) > +{ > + while (*uuid1 && *uuid2) > + { > + while (*uuid1 =3D=3D '-') > + uuid1++; > + while (*uuid2 =3D=3D '-') > + uuid2++; > + > + if (grub_tolower (*uuid1) !=3D grub_tolower (*uuid2)) > + break; > + > + uuid1++; > + uuid2++; > + } > + > + return (int) grub_tolower ((grub_uint8_t) *uuid1) > + - (int) grub_tolower ((grub_uint8_t) *uuid2); > +} > + > /* > * Note that these differ from the C standard's definitions of strtol, > * strtoul(), and strtoull() by the addition of two const qualifiers on = the end > --=20 > 2.25.1 >=20 --8NvZYKFJsRX2Djef Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl8i5hsACgkQVbJhu7ck PpQ4xA/9EXI8LA4SHONM2IynhmoXlArHCTqgHc/TV94Dl3914+gpik1pTRmfGorO JuLxiO0wIAhlY/sEq5FupjAqdpjvncMb3Bp8vVIGTC5k9K+Mzygdj4DZfRiYUirl I1c8nbrDlBtHAFBBRy3JwhLj9HA4j/hgnJZIH6RgJ5cG1aNSLXeErk/4ehrgwX0s yD9CxBvmmAC6fejkzSJ+y5X2ScZhwubekczWoJegkP4+fHwseCjLrU3cBHESUpTr lVWrQLL1x5xwbq7n+MGORQO8gnuEfJPMCWdIBWeGfPbbLBhnIIk8h3eyHc1Oc7XX wRjrILTWYGjEVL7HsDDzsrW629y/cHWC1++IehXeq12O3LbbqN1ch9Z4kFETy8uS kBKOgVjA8/LqC/N/mxQmPBPv3p5U/uHtsEyGlmfnIcfbikcEIovdRzDyM1Hlvxot QBPgQeuwrmiypIrGAXG0niuNcH1HWaWzlEA9JONQQvh22Tzo5M1snbgS71IjbQ7S pXaaMK+EXazOCPz3gkTEgb6/gfBQ/r8dhIQeu/yYDaQflbxJ9Z0yJO6La25TZxJd HOVPT2OukRXAe6NOsZROsyY6ZLPlOklGYhoPRxnY1N9lutRtYCcRnUW7TJ5jXtEk u27bQEAeOxhZQEZS9zbtcokBClbZAzvdIAv4UU5SQqGGhNK0mgk= =kgkE -----END PGP SIGNATURE----- --8NvZYKFJsRX2Djef--