Skip to contentSkip to conversation

grub-install: Delay copying files to grubdir after install_device was validated.

PATCH Superseded Mate Kukri 2 participants 2 messages Nov 22, 2023

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Mate Kukri

author
#0 lore raw

PATCH v2 1/1 grub-install: Delay copying files to grubdir after install_device was validated.

Previously grub-install copied modules to grubdir before doing any validation on the install_device.

When grub-install was called with an invalid install_device, modules were already copied to /boot before it found out and was forced to rely on atexit rollback.

This patch delays copying the modules after at least some install_device validation was done, and thus reduces reliance on successful rollback.

---
 util/grub-install.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
util/grub-install.c +7 -7
index 1ad04db36..fd799a75f 100644
@@ -1291,13 +1291,6 @@ main (int argc, char *argv[])
 	}
     }
 
-  grub_install_copy_files (grub_install_source_directory,
-			   grubdir, platform);
-
-  char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
-  if (!grub_util_is_regular (envfile))
-    grub_util_create_envblk_file (envfile);
-
   size_t ndev = 0;
 
   /* Write device to a variable so we don't have to traverse /dev every time.  */
@@ -1419,6 +1412,13 @@ main (int argc, char *argv[])
 	}
     }
 
+  grub_install_copy_files (grub_install_source_directory,
+                           grubdir, platform);
+
+  char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
+  if (!grub_util_is_regular (envfile))
+    grub_util_create_envblk_file (envfile);
+
   if (!have_abstractions)
     {
       if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0)
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 47 lines · Mate Kukri

Previously grub-install copied modules to grubdir before doing any validation on the install_device.

When grub-install was called with an invalid install_device, modules were already copied to /boot before it found out and was forced to rely on atexit rollback.

This patch delays copying the modules after at least some install_device validation was done, and thus reduces reliance on successful rollback.

---
 util/grub-install.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
util/grub-install.c +7 -7
index 1ad04db36..fd799a75f 100644
@@ -1291,13 +1291,6 @@ main (int argc, char *argv[])
 	}
     }
 
-  grub_install_copy_files (grub_install_source_directory,
-			   grubdir, platform);
-
-  char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
-  if (!grub_util_is_regular (envfile))
-    grub_util_create_envblk_file (envfile);
-
   size_t ndev = 0;
 
   /* Write device to a variable so we don't have to traverse /dev every time.  */
@@ -1419,6 +1412,13 @@ main (int argc, char *argv[])
 	}
     }
 
+  grub_install_copy_files (grub_install_source_directory,
+                           grubdir, platform);
+
+  char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
+  if (!grub_util_is_regular (envfile))
+    grub_util_create_envblk_file (envfile);
+
   if (!have_abstractions)
     {
       if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0)
Signature · 1 line
2.39.2

This looks reasonable to me, there is some more code there writing to the grub dir before the disk has been identified:

grub_util_unlink (load_cfg);

and following lines; it may make sense to move them later too, I think it would overall make more sense to have them where we generate an empty grubenv.

But aside from that happy to add my

Signature · 7 lines
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel