]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
devmapper: check for valid device abstraction in get_grub_dev
authorAndrei Borzenkov <arvidjaar@gmail.com>
Sat, 26 Dec 2015 18:45:22 +0000 (21:45 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Sat, 26 Dec 2015 18:45:22 +0000 (21:45 +0300)
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
grub-core/osdep/linux/getroot.c

index 64419f678ce3c6427e6edba507aae90c0d64e648..05eda500a4060ac76aef94c6a16d9a1116f6aa39 100644 (file)
@@ -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 *
index 3978c71143d56b8b136df78c28b743944858420d..10480b646241d6ca8ede25427e433178c00cea57 100644 (file)
@@ -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:
       {