From 3bca85b4184f74995a7cc2791e432173fde26d34 Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Sat, 26 Dec 2015 21:45:22 +0300 Subject: [PATCH] devmapper: check for valid device abstraction in get_grub_dev This was lost when code was refactored. Patch restores previous behavior. It is still not clear whether this is the right one. Due to the way we detect DM abstraction, partitions on DM are skipped, we fall through to generic detection which ends up in assuming parent device is BIOS disk. It is useful to install GRUB on VM disk from the host. But it also means that GRUB will mistakenly allow install on real system as well. For now let's fix regression; future behavior needs to be discussed. Closes: 45163 --- grub-core/osdep/devmapper/getroot.c | 33 +++++++++++++++++------------ grub-core/osdep/linux/getroot.c | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/grub-core/osdep/devmapper/getroot.c b/grub-core/osdep/devmapper/getroot.c index 64419f678..05eda500a 100644 --- a/grub-core/osdep/devmapper/getroot.c +++ b/grub-core/osdep/devmapper/getroot.c @@ -223,11 +223,14 @@ grub_util_get_devmapper_grub_dev (const char *os_dev) uuid = get_dm_uuid (os_dev); if (!uuid) return NULL; - - if (strncmp (uuid, "LVM-", sizeof ("LVM-") - 1) == 0) + + switch (grub_util_get_dev_abstraction (os_dev)) { + case GRUB_DEV_ABSTRACTION_LVM: + { unsigned i; int dashes[] = { 0, 6, 10, 14, 18, 22, 26, 32, 38, 42, 46, 50, 54, 58}; + grub_dev = xmalloc (grub_strlen (uuid) + 40); optr = grub_stpcpy (grub_dev, "lvmid/"); for (i = 0; i < ARRAY_SIZE (dashes) - 1; i++) @@ -245,19 +248,23 @@ grub_util_get_devmapper_grub_dev (const char *os_dev) return grub_dev; } - if (strncmp (uuid, "CRYPT-LUKS1-", sizeof ("CRYPT-LUKS1-") - 1) == 0) - { - char *dash; - dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); - if (dash) - *dash = 0; - grub_dev = grub_xasprintf ("cryptouuid/%s", - uuid + sizeof ("CRYPT-LUKS1-") - 1); + case GRUB_DEV_ABSTRACTION_LUKS: + { + char *dash; + + dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); + if (dash) + *dash = 0; + grub_dev = grub_xasprintf ("cryptouuid/%s", + uuid + sizeof ("CRYPT-LUKS1-") - 1); + grub_free (uuid); + return grub_dev; + } + + default: grub_free (uuid); - return grub_dev; + return NULL; } - grub_free (uuid); - return NULL; } char * diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 3978c7114..10480b646 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -1075,7 +1075,7 @@ grub_util_get_grub_dev_os (const char *os_dev) switch (grub_util_get_dev_abstraction (os_dev)) { /* Fallback for non-devmapper build. In devmapper-builds LVM is handled - in rub_util_get_devmapper_grub_dev and this point isn't reached. + in grub_util_get_devmapper_grub_dev and this point isn't reached. */ case GRUB_DEV_ABSTRACTION_LVM: {