nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0487-powerpc-adjust-setting-of-prefix-for-signed-binary-c.patch

f20682
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f20682
From: Daniel Axtens <dja@axtens.net>
f20682
Date: Mon, 19 Jul 2021 14:35:55 +1000
f20682
Subject: [PATCH] powerpc: adjust setting of prefix for signed binary case
f20682
f20682
On RHEL-signed powerpc grub, we sign a grub with -p /grub2 and expect
f20682
that there's a boot partition.
f20682
f20682
Unfortunately grub_set_prefix_and_root tries to convert this to
f20682
($fwdevice)/grub2. This ends up being (ieee1275/disk)/grub2 and that
f20682
falls apart pretty quickly - there's no file-system on ieee1275/disk,
f20682
and it makes the search routine try things like
f20682
(ieee1275/disk,msdos2)(ieee1275/disk)/grub2 which also doesn't work.
f20682
f20682
Detect if we would be about to create (ieee1275/disk)/path and don't:
f20682
preserve a prefix of /path instead and hope the search later finds us.
f20682
f20682
Related: rhbz#1899864
f20682
f20682
Signed-off-by: Daniel Axtens <dja@axtens.net>
f20682
---
f20682
 grub-core/kern/main.c | 38 +++++++++++++++++++++++++++++++++-----
f20682
 1 file changed, 33 insertions(+), 5 deletions(-)
f20682
f20682
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
f20682
index 9bf6a8b231a..25dbcfef1f6 100644
f20682
--- a/grub-core/kern/main.c
f20682
+++ b/grub-core/kern/main.c
f20682
@@ -215,13 +215,41 @@ grub_set_prefix_and_root (void)
f20682
   if (device)
f20682
     {
f20682
       char *prefix_set;
f20682
-    
f20682
-      prefix_set = grub_xasprintf ("(%s)%s", device, path ? : "");
f20682
-      if (prefix_set)
f20682
+
f20682
+#ifdef __powerpc__
f20682
+      /* We have to be careful here on powerpc-ieee1275 + signed grub. We
f20682
+	 will have signed something with a prefix that doesn't have a device
f20682
+	 because we cannot know in advance what partition we're on.
f20682
+
f20682
+	 We will have had !device earlier, so we will have set device=fwdevice
f20682
+	 However, we want to make sure we do not end up setting prefix to be
f20682
+	 ($fwdevice)/path, because we will then end up trying to boot or search
f20682
+	 based on a prefix of (ieee1275/disk)/path, which will not work because
f20682
+	 it's missing a partition.
f20682
+
f20682
+	 Also:
f20682
+	  - You can end up with a device with an FS directly on it, without
f20682
+	    a partition, e.g. ieee1275/cdrom.
f20682
+
f20682
+	  - powerpc-ieee1275 + grub-install sets e.g. prefix=(,gpt2)/path,
f20682
+	    which will have now been extended to device=$fwdisk,partition
f20682
+	    and path=/path
f20682
+
f20682
+	 So we only need to act if device = ieee1275/disk exactly.
f20682
+       */
f20682
+      if (grub_strncmp (device, "ieee1275/disk", 14) == 0)
f20682
+        grub_env_set ("prefix", path);
f20682
+      else
f20682
+#endif
f20682
 	{
f20682
-	  grub_env_set ("prefix", prefix_set);
f20682
-	  grub_free (prefix_set);
f20682
+	  prefix_set = grub_xasprintf ("(%s)%s", device, path ? : "");
f20682
+	  if (prefix_set)
f20682
+	  {
f20682
+	    grub_env_set ("prefix", prefix_set);
f20682
+	    grub_free (prefix_set);
f20682
+	  }
f20682
 	}
f20682
+
f20682
       grub_env_set ("root", device);
f20682
     }
f20682