Dash:
[t2.git] / package / boot / grub2 / uuid-hyphens.patch
blob92efcae33f53cb0a82cd14ffe49274f9de6e2d06
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/*/grub2/uuid-hyphens.patch
5 # Copyright (C) 2017 - 2021 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 From f723c22cb7d8a5a6633eaa0682e024e667fb581a Mon Sep 17 00:00:00 2001
18 From: John Lane <john@lane.uk.net>
19 Date: Fri, 26 Jun 2015 22:48:03 +0100
20 Subject: [PATCH 5/5] Cryptomount support for hyphens in UUID
22 Rebased and added luks2 support:
24 - René Rebe <rene@exactcode.de>
26 ---
27 grub-core/disk/cryptodisk.c | 20 +++++++++++++++++---
28 grub-core/disk/luks.c | 26 ++++++++------------------
29 include/grub/cryptodisk.h | 2 ++
30 3 files changed, 27 insertions(+), 21 deletions(-)
32 diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
33 index cd5cfc9..d36d16b 100644
34 --- a/grub-core/disk/cryptodisk.c
35 +++ b/grub-core/disk/cryptodisk.c
36 @@ -113,6 +113,20 @@ gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b)
40 +int
41 +grub_cryptodisk_uuidcmp(const char *uuid_a, const char *uuid_b)
43 + while ((*uuid_a != '\0') && (*uuid_b != '\0'))
44 + {
45 + while (*uuid_a == '-') uuid_a++;
46 + while (*uuid_b == '-') uuid_b++;
47 + if (grub_toupper(*uuid_a) != grub_toupper(*uuid_b)) break;
48 + uuid_a++;
49 + uuid_b++;
50 + }
51 + return (*uuid_a == '\0') && (*uuid_b == '\0');
54 static gcry_err_code_t
55 grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher,
56 void *out, void *in, grub_size_t size,
57 @@ -507,8 +521,8 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)
58 if (grub_memcmp (name, "cryptouuid/", sizeof ("cryptouuid/") - 1) == 0)
60 for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
61 - if (grub_strcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) == 0)
62 - break;
63 + if (grub_cryptodisk_uuidcmp(name + sizeof ("cryptouuid/") - 1, dev->uuid))
64 + break;
66 else
68 @@ -739,7 +753,7 @@ grub_cryptodisk_get_by_uuid (const char *uuid)
70 grub_cryptodisk_t dev;
71 for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
72 - if (grub_strcasecmp (dev->uuid, uuid) == 0)
73 + if (grub_cryptodisk_uuidcmp(dev->uuid, uuid))
74 return dev;
75 return NULL;
77 --- grub-2.02/grub-core/disk/luks.c.orig 2015-09-02 22:10:53.000000000 +0200
78 +++ grub-2.02/grub-core/disk/luks.c 2017-12-03 18:02:29.093945562 +0100
79 @@ -69,9 +69,7 @@
80 int check_boot)
82 grub_cryptodisk_t newdev;
83 - const char *iptr;
84 struct grub_luks_phdr header;
85 - char *optr;
86 char uuid[sizeof (header.uuid) + 1];
87 char ciphername[sizeof (header.cipherName) + 1];
88 char ciphermode[sizeof (header.cipherMode) + 1];
89 @@ -94,20 +94,6 @@
90 return NULL;
92 grub_memset (uuid, 0, sizeof (uuid));
93 - optr = uuid;
94 - for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)];
95 - iptr++)
96 - {
97 - if (*iptr != '-')
98 - *optr++ = *iptr;
99 - }
100 - *optr = 0;
102 - if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0)
104 - grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
105 - return NULL;
108 /* Make sure that strings are null terminated. */
109 grub_memcpy (ciphername, header.cipherName, sizeof (header.cipherName));
110 @@ -125,6 +108,14 @@
111 ciphermode[sizeof (header.cipherMode)] = 0;
112 grub_memcpy (hashspec, header.hashSpec, sizeof (header.hashSpec));
113 hashspec[sizeof (header.hashSpec)] = 0;
114 + grub_memcpy (uuid, header.uuid, sizeof (header.uuid));
115 + uuid[sizeof (header.uuid)] = 0;
117 + if ( check_uuid && ! grub_cryptodisk_uuidcmp(check_uuid, uuid))
119 + grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
120 + return NULL;
123 ciph = grub_crypto_lookup_cipher_by_name (ciphername);
124 if (!ciph)
125 diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h
126 index 4076412..a564f2c 100644
127 --- a/include/grub/cryptodisk.h
128 +++ b/include/grub/cryptodisk.h
129 @@ -167,4 +167,6 @@ grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk);
130 grub_cryptodisk_t grub_cryptodisk_create (grub_disk_t disk, char *uuid,
131 char *ciphername, char *ciphermode, char *digest);
133 +int
134 +grub_cryptodisk_uuidcmp(const char *uuid_a, const char *uuid_b);
135 #endif
137 2.1.2
139 --- grub-2.06~rc1/grub-core/disk/luks2.c.vanilla 2021-03-13 13:33:43.247134523 +0100
140 +++ grub-2.06~rc1/grub-core/disk/luks2.c 2021-03-13 13:39:37.093113432 +0100
141 @@ -353,7 +353,6 @@
142 grub_cryptodisk_t cryptodisk;
143 grub_luks2_header_t header;
144 char uuid[sizeof (header.uuid) + 1];
145 - grub_size_t i, j;
147 if (check_boot)
148 return NULL;
149 @@ -364,13 +363,14 @@
150 return NULL;
153 - for (i = 0, j = 0; i < sizeof (header.uuid); i++)
154 - if (header.uuid[i] != '-')
155 - uuid[j++] = header.uuid[i];
156 - uuid[j] = '\0';
157 + grub_memcpy (uuid, header.uuid, sizeof (header.uuid));
158 + uuid[sizeof (header.uuid)] = 0;
160 - if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0)
161 - return NULL;
162 + if ( check_uuid && ! grub_cryptodisk_uuidcmp(check_uuid, uuid))
164 + grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
165 + return NULL;
168 cryptodisk = grub_zalloc (sizeof (*cryptodisk));
169 if (!cryptodisk)