]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2005-02-14 Guillem Jover <guillem@hadrons.org>
authormarco_g <marco_g@localhost>
Mon, 14 Feb 2005 18:41:33 +0000 (18:41 +0000)
committermarco_g <marco_g@localhost>
Mon, 14 Feb 2005 18:41:33 +0000 (18:41 +0000)
* include/grub/dl.h (grub_dl_check_header): New prototype.
(grub_arch_dl_check_header): Change return type to grub_err_t,
remove size parameter and export function.  Update all callers.
* kern/dl.c (grub_dl_check_header): New function.
(grub_dl_load_core): Use `grub_dl_check_header' instead of
`grub_arch_dl_check_header'.  Check ELF type.  Check if sections
are inside the core.
* kern/i386/dl.c (grub_arch_dl_check_header): Remove arch
independent ELF header checks.
* kern/powerpc/dl.c (grub_arch_dl_check_header): Likewise.
* loader/i386/pc/multiboot.c (grub_rescue_cmd_multiboot): Use
`grub_dl_check_header' instead of explicit checks.  Check for the
ELF type.
* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Use
`grub_dl_check_header' instead of explicit checks.  Remove arch
specific ELF header checks.

ChangeLog
include/grub/dl.h
kern/dl.c
kern/i386/dl.c
kern/powerpc/dl.c
loader/i386/pc/multiboot.c
loader/powerpc/ieee1275/linux.c
util/grub-emu.c

index 00bbf6b6cd7facf8c613630ee256bc3a1637b638..328274253c60e41fef79b16ffcca6e62579ecf0c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2005-02-14  Guillem Jover  <guillem@hadrons.org>
+
+       * include/grub/dl.h (grub_dl_check_header): New prototype.
+       (grub_arch_dl_check_header): Change return type to grub_err_t,
+       remove size parameter and export function.  Update all callers.
+       * kern/dl.c (grub_dl_check_header): New function.
+       (grub_dl_load_core): Use `grub_dl_check_header' instead of
+       `grub_arch_dl_check_header'.  Check ELF type.  Check if sections
+       are inside the core.
+       * kern/i386/dl.c (grub_arch_dl_check_header): Remove arch
+       independent ELF header checks.
+       * kern/powerpc/dl.c (grub_arch_dl_check_header): Likewise.
+       * loader/i386/pc/multiboot.c (grub_rescue_cmd_multiboot): Use
+       `grub_dl_check_header' instead of explicit checks.  Check for the
+       ELF type.
+       * loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Use
+       `grub_dl_check_header' instead of explicit checks.  Remove arch
+       specific ELF header checks.
+
 2005-02-13  Hollis Blanchard  <hollis@penguinppc.org>
 
        * conf/powerpc-ieee1275.rmk (pkgdata_MODULES): Add ls.mod.
index 3ddff6d81a26298e8f9d5b1027830858ccd9bd3d..aec2bd132b960dfdbaf84f2f0fd9940a128a717b 100644 (file)
@@ -1,7 +1,7 @@
 /* dl.h - types and prototypes for loadable module support */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002, 2004  Free Software Foundation, Inc.
+ *  Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -70,6 +70,7 @@ struct grub_dl
 };
 typedef struct grub_dl *grub_dl_t;
 
+grub_err_t EXPORT_FUNC(grub_dl_check_header) (void *ehdr, grub_size_t size);
 grub_dl_t EXPORT_FUNC(grub_dl_load_file) (const char *filename);
 grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
 grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
@@ -84,7 +85,7 @@ grub_err_t EXPORT_FUNC(grub_dl_register_symbol) (const char *name, void *addr,
                                            grub_dl_t mod);
 void *EXPORT_FUNC(grub_dl_resolve_symbol) (const char *name);
 
-int grub_arch_dl_check_header (void *ehdr, grub_size_t size);
+grub_err_t grub_arch_dl_check_header (void *ehdr);
 grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr);
 
 #endif /* ! GRUB_DL_H */
index e6a172c7af03e2fd04c57a5212566fe19a114b12..2e52948ce1246c685922a15ade251d0af32b4d23 100644 (file)
--- a/kern/dl.c
+++ b/kern/dl.c
@@ -1,7 +1,7 @@
 /* dl.c - loadable module support */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002, 2003, 2004  Free Software Foundation, Inc.
+ *  Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -238,6 +238,29 @@ grub_dl_get_section_addr (grub_dl_t mod, unsigned n)
   return 0;
 }
 
+/* Check if EHDR is a valid ELF header.  */
+grub_err_t
+grub_dl_check_header (void *ehdr, grub_size_t size)
+{
+  Elf_Ehdr *e = ehdr;
+
+  /* Check the header size.  */
+  if (size < sizeof (Elf_Ehdr))
+    return grub_error (GRUB_ERR_BAD_OS, "ELF header smaller than expected");
+
+  /* Check the magic numbers.  */
+  if (grub_arch_dl_check_header (ehdr)
+      || e->e_ident[EI_MAG0] != ELFMAG0
+      || e->e_ident[EI_MAG1] != ELFMAG1
+      || e->e_ident[EI_MAG2] != ELFMAG2
+      || e->e_ident[EI_MAG3] != ELFMAG3
+      || e->e_ident[EI_VERSION] != EV_CURRENT
+      || e->e_version != EV_CURRENT)
+    return grub_error (GRUB_ERR_BAD_OS, "invalid arch independent ELF magic");
+
+  return GRUB_ERR_NONE;
+}
+
 /* Load all segments from memory specified by E.  */
 static grub_err_t
 grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
@@ -497,12 +520,22 @@ grub_dl_load_core (void *addr, grub_size_t size)
   grub_dl_t mod;
   
   e = addr;
-  if (! grub_arch_dl_check_header (e, size))
+  if (grub_dl_check_header (e, size))
+    return 0;
+  
+  if (e->e_type != ET_REL)
     {
-      grub_error (GRUB_ERR_BAD_MODULE, "invalid ELF header");
+      grub_error (GRUB_ERR_BAD_MODULE, "invalid ELF file type");
       return 0;
     }
-  
+
+  /* Make sure that every section is within the core.  */
+  if (size < e->e_shoff + e->e_shentsize * e->e_shnum)
+    {
+      grub_error (GRUB_ERR_BAD_OS, "ELF sections outside core");
+      return 0;
+    }
+
   mod = (grub_dl_t) grub_malloc (sizeof (*mod));
   if (! mod)
     return 0;
index 7e563c7d445d3c53e1f18d3b1c86498a675d9aa1..2c8d0ad1ae3d30817752e2c191aa9890eee90b5c 100644 (file)
@@ -1,7 +1,7 @@
 /* dl-386.c - arch-dependent part of loadable module support */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002  Free Software Foundation, Inc.
+ *  Copyright (C) 2002, 2005  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include <grub/err.h>
 
 /* Check if EHDR is a valid ELF header.  */
-int
-grub_arch_dl_check_header (void *ehdr, grub_size_t size)
+grub_err_t
+grub_arch_dl_check_header (void *ehdr)
 {
   Elf32_Ehdr *e = ehdr;
 
-  /* Check the header size.  */
-  if (size < sizeof (Elf32_Ehdr))
-    return 0;
-
   /* Check the magic numbers.  */
-  if (e->e_ident[EI_MAG0] != ELFMAG0
-      || e->e_ident[EI_MAG1] != ELFMAG1
-      || e->e_ident[EI_MAG2] != ELFMAG2
-      || e->e_ident[EI_MAG3] != ELFMAG3
-      || e->e_version != EV_CURRENT
-      || e->e_ident[EI_CLASS] != ELFCLASS32
+  if (e->e_ident[EI_CLASS] != ELFCLASS32
       || e->e_ident[EI_DATA] != ELFDATA2LSB
-      || e->e_machine != EM_386
-      || e->e_type != ET_REL)
-    return 0;
+      || e->e_machine != EM_386)
+    return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic");
 
-  /* Make sure that every section is within the core.  */
-  if (size < e->e_shoff + e->e_shentsize * e->e_shnum)
-    return 0;
-
-  return 1;
+  return GRUB_ERR_NONE;
 }
 
 /* Relocate symbols.  */
index 1b965c70b0c047eb0d81644162901730602caae1..b9d01a951fc0727cb1ae3db1b4b1c3084bf49310 100644 (file)
@@ -1,7 +1,7 @@
 /* dl.c - arch-dependent part of loadable module support */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002, 2004  Free Software Foundation, Inc.
+ *  Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include <grub/err.h>
 
 /* Check if EHDR is a valid ELF header.  */
-int
-grub_arch_dl_check_header (void *ehdr, grub_size_t size)
+grub_err_t
+grub_arch_dl_check_header (void *ehdr)
 {
   Elf32_Ehdr *e = ehdr;
 
-  /* Check the header size.  */
-  if (size < sizeof (Elf32_Ehdr))
-    return 0;
-
   /* Check the magic numbers.  */
-  if (!((e->e_ident[EI_MAG0] == ELFMAG0) 
-       && (e->e_ident[EI_MAG1] == ELFMAG1)
-       && (e->e_ident[EI_MAG2] == ELFMAG2) 
-       && (e->e_ident[EI_MAG3] == ELFMAG3)
-       && (e->e_ident[EI_CLASS] == ELFCLASS32) 
-       && (e->e_ident[EI_DATA] == ELFDATA2MSB)
-       && (e->e_ident[EI_VERSION] == EV_CURRENT) 
-       && (e->e_type == ET_REL) && (e->e_machine == EM_PPC) 
-       && (e->e_version == EV_CURRENT)))
-    return 0;
-  
-  /* Make sure that every section is within the core.  */
-  if (size < e->e_shoff + e->e_shentsize * e->e_shnum)
-    return 0;
+  if (e->e_ident[EI_CLASS] != ELFCLASS32
+      || e->e_ident[EI_DATA] != ELFDATA2MSB
+      || e->e_machine != EM_PPC)
+    return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic");
 
-  return 1;
+  return GRUB_ERR_NONE;
 }
 
 
index de39d7ded156b91832660a688bd263b77eadb69a..32b9abf919cc51e0d7633270258a147d5c3d0de4 100644 (file)
@@ -1,7 +1,7 @@
 /* multiboot.c - boot a multiboot OS image. */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003, 2004  Free Software Foundation, Inc.
+ *  Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -140,20 +140,18 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
 
   ehdr = (Elf32_Ehdr *) buffer;
 
-  if (!((ehdr->e_ident[EI_MAG0] == ELFMAG0) 
-       && (ehdr->e_ident[EI_MAG1] == ELFMAG1)
-       && (ehdr->e_ident[EI_MAG2] == ELFMAG2) 
-       && (ehdr->e_ident[EI_MAG3] == ELFMAG3)
-       && (ehdr->e_ident[EI_CLASS] == ELFCLASS32) 
-       && (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-       && (ehdr->e_ident[EI_VERSION] == EV_CURRENT) 
-       && (ehdr->e_type == ET_EXEC) && (ehdr->e_machine == EM_386) 
-       && (ehdr->e_version == EV_CURRENT)))
+  if (grub_dl_check_header (ehdr, sizeof(*ehdr)))
     {
       grub_error (GRUB_ERR_UNKNOWN_OS, "No valid ELF header found");
       goto fail;
     }
 
+  if (ehdr->e_type != ET_EXEC)
+    {
+      grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type");
+      goto fail;
+    }
+
   /* FIXME: Should we support program headers at strange locations?  */
   if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_MB_SEARCH)
     {
index d5d65e61312df79baca3edff6d06bdafc6fdb043..f02448cb96a1f77da6bc1341cc309d27f311d746 100644 (file)
@@ -1,7 +1,7 @@
 /* linux.c - boot Linux */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003, 2004  Free Software Foundation, Inc.
+ *  Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -124,15 +124,7 @@ grub_rescue_cmd_linux (int argc, char *argv[])
       goto fail;
     }
   
-  if (!((ehdr.e_ident[EI_MAG0] == ELFMAG0) 
-       && (ehdr.e_ident[EI_MAG1] == ELFMAG1)
-       && (ehdr.e_ident[EI_MAG2] == ELFMAG2) 
-       && (ehdr.e_ident[EI_MAG3] == ELFMAG3)
-       && (ehdr.e_ident[EI_CLASS] == ELFCLASS32) 
-       && (ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
-       && (ehdr.e_ident[EI_VERSION] == EV_CURRENT) 
-       && (ehdr.e_type == ET_EXEC) && (ehdr.e_machine == EM_PPC) 
-       && (ehdr.e_version == EV_CURRENT)))
+  if (grub_dl_check_header (&ehdr, sizeof(ehdr)))
     {
       grub_error (GRUB_ERR_UNKNOWN_OS, "No valid ELF header found");
       goto fail;
@@ -145,20 +137,6 @@ grub_rescue_cmd_linux (int argc, char *argv[])
       goto fail;
     }
 
-  if (ehdr.e_machine != EM_PPC)
-    {
-      grub_error (GRUB_ERR_UNKNOWN_OS,
-                 "This ELF file is not for the PPC32\n");
-      goto fail;
-    }
-  
-  if (ehdr.e_version != EV_CURRENT)
-    {
-      grub_error (GRUB_ERR_UNKNOWN_OS,
-                 "Invalid ELF version\n");
-      goto fail;
-    }
-
   /* Read the sections.  */
   entry = ehdr.e_entry;
   if (entry == 0xc0000000)
index b0a80e398489b026d709d595c07338222a4f2054..766b709f65178b6d791e7aacef8b10861099b2ef 100644 (file)
@@ -51,11 +51,10 @@ grub_arch_modules_addr (void)
   return 0;
 }
 
-int
-grub_arch_dl_check_header (void *ehdr, grub_size_t size)
+grub_err_t
+grub_arch_dl_check_header (void *ehdr)
 {
   (void) ehdr;
-  (void) size;
 
   return GRUB_ERR_BAD_MODULE;
 }