From ee12785f75eb255930902779964401544becf9f8 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Sat, 30 May 2020 14:25:11 +0200 Subject: [PATCH] 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 Reviewed-by: Daniel Kiper --- grub-core/disk/luks2.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index a48bddf5d..31d7166fc 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -346,6 +346,8 @@ luks2_scan (grub_disk_t disk, const char *check_uuid, int check_boot) { grub_cryptodisk_t cryptodisk; grub_luks2_header_t header; + char uuid[sizeof (header.uuid) + 1]; + grub_size_t i, j; if (check_boot) return NULL; @@ -356,16 +358,21 @@ luks2_scan (grub_disk_t disk, const char *check_uuid, int check_boot) return NULL; } - if (check_uuid && grub_strcasecmp (check_uuid, header.uuid) != 0) + for (i = 0, j = 0; i < sizeof (header.uuid); i++) + if (header.uuid[i] != '-') + uuid[j++] = header.uuid[i]; + uuid[j] = '\0'; + + if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0) return NULL; cryptodisk = grub_zalloc (sizeof (*cryptodisk)); if (!cryptodisk) return NULL; - COMPILE_TIME_ASSERT (sizeof (cryptodisk->uuid) >= sizeof (header.uuid)); + COMPILE_TIME_ASSERT (sizeof (cryptodisk->uuid) >= sizeof (uuid)); + grub_memcpy (cryptodisk->uuid, uuid, sizeof (uuid)); - grub_memcpy (cryptodisk->uuid, header.uuid, sizeof (header.uuid)); cryptodisk->modname = "luks2"; return cryptodisk; }