Skip to contentSkip to conversation

grub: Eliminate recursive reads of the same device in grub_dl_load_file().

PATCH David Miller 1 participant 2 messages Apr 13, 2009

lore
Share & tools
lore
#0 lore raw

Openfirmware block device drivers do not allow for multiple concurrent opens of the same device. It simply does not work.

Fortunately grub doesn't actually need to do this, it just happens to do so. Here is the fix for the case of module dependency handling.

The other case that hits this problem is in the FS_UUID support code. I have patches later which will fix that case too, but that one is a little more involved as we have to fix some bugs in the the ieee1275 devalias iterator first (for one, it doesn't stop when the callback returns non-zero as every other iterator in grub2 does).

2009-04-12 David S. Miller <[email protected]>

* kern/dl.c (grub_dl_load_file): Close file immediately when we are done using it.

---
 kern/dl.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)
kern/dl.c +19 -9
index bc21403..458ad58 100644
@@ -584,7 +584,7 @@ grub_dl_load_core (void *addr, grub_size_t size)
 grub_dl_t
 grub_dl_load_file (const char *filename)
 {
-  grub_file_t file;
+  grub_file_t file = NULL;
   grub_ssize_t size;
   void *core = 0;
   grub_dl_t mod = 0;
@@ -596,21 +596,31 @@ grub_dl_load_file (const char *filename)
   size = grub_file_size (file);
   core = grub_malloc (size);
   if (! core)
-    goto failed;
+    {
+      grub_file_close (file);
+      return 0;
+    }
 
   if (grub_file_read (file, core, size) != (int) size)
-    goto failed;
+    {
+      grub_file_close (file);
+      grub_free (core);
+      return 0;
+    }
+
+  /* We must close this before we try to process dependencies.
+     Some disk backends do not handle gracefully multiple concurrent
+     opens of the same device.  */
+  grub_file_close (file);
 
   mod = grub_dl_load_core (core, size);
   if (! mod)
-    goto failed;
+    {
+      grub_free (core);
+      return 0;
+    }
   
   mod->ref_count = 0;
-
- failed:
-  grub_file_close (file);
-  grub_free (core);
-
   return mod;
 }
 
Signature · 1 line
1.6.2.3
#1 lore raw

From: David Miller <[email protected]>
Date: Sun, 12 Apr 2009 23:56:11 -0700 (PDT)

Quoted 13 lines

Openfirmware block device drivers do not allow for multiple concurrent opens of the same device. It simply does not work.

Fortunately grub doesn't actually need to do this, it just happens to do so. Here is the fix for the case of module dependency handling.

The other case that hits this problem is in the FS_UUID support code. I have patches later which will fix that case too, but that one is a little more involved as we have to fix some bugs in the the ieee1275 devalias iterator first (for one, it doesn't stop when the callback returns non-zero as every other iterator in grub2 does).

Quoted 4 lines

2009-04-12 David S. Miller <[email protected]>

* kern/dl.c (grub_dl_load_file): Close file immediately when we are done using it.

I've committed this change as well.