Skip to content

Commit ee12785

Browse files
pks-tDaniel Kiper
authored and
Daniel Kiper
committed
luks2: Strip dashes off of the UUID
The UUID header for LUKS2 uses a format with dashes, same as for LUKS(1). But while we strip these dashes for the latter, we don't for the former. This isn't wrong per se, but it's definitely inconsistent for users as they need to use the dashed format for LUKS2 and the non-dashed format for LUKS when e.g. calling "cryptomount -u $UUID". Fix this inconsistency by stripping dashes off of the LUKS2 UUID. Signed-off-by: Patrick Steinhardt <[email protected]> Reviewed-by: Daniel Kiper <[email protected]>
1 parent 6efd04f commit ee12785

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

grub-core/disk/luks2.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ luks2_scan (grub_disk_t disk, const char *check_uuid, int check_boot)
346346
{
347347
grub_cryptodisk_t cryptodisk;
348348
grub_luks2_header_t header;
349+
char uuid[sizeof (header.uuid) + 1];
350+
grub_size_t i, j;
349351

350352
if (check_boot)
351353
return NULL;
@@ -356,16 +358,21 @@ luks2_scan (grub_disk_t disk, const char *check_uuid, int check_boot)
356358
return NULL;
357359
}
358360

359-
if (check_uuid && grub_strcasecmp (check_uuid, header.uuid) != 0)
361+
for (i = 0, j = 0; i < sizeof (header.uuid); i++)
362+
if (header.uuid[i] != '-')
363+
uuid[j++] = header.uuid[i];
364+
uuid[j] = '\0';
365+
366+
if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0)
360367
return NULL;
361368

362369
cryptodisk = grub_zalloc (sizeof (*cryptodisk));
363370
if (!cryptodisk)
364371
return NULL;
365372

366-
COMPILE_TIME_ASSERT (sizeof (cryptodisk->uuid) >= sizeof (header.uuid));
373+
COMPILE_TIME_ASSERT (sizeof (cryptodisk->uuid) >= sizeof (uuid));
374+
grub_memcpy (cryptodisk->uuid, uuid, sizeof (uuid));
367375

368-
grub_memcpy (cryptodisk->uuid, header.uuid, sizeof (header.uuid));
369376
cryptodisk->modname = "luks2";
370377
return cryptodisk;
371378
}

0 commit comments

Comments
 (0)