]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/loader/multiboot_elfxx.c: Check eip after v2p translation
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 16 Jul 2013 16:37:44 +0000 (18:37 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 16 Jul 2013 16:37:44 +0000 (18:37 +0200)
and not before.
Reported by: Leon Drugi.

ChangeLog
grub-core/loader/multiboot_elfxx.c

index 57af49bb27c7249d8abec838aee11bc07b4033e3..69492ef8582569200f03aef2ee04431a3aea805a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-07-16  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/loader/multiboot_elfxx.c: Check eip after v2p translation
+       and not before.
+       Reported by: Leon Drugi.
+
 2013-07-16  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/kern/powerpc/ieee1275/startup.S: Handle unaligned bss.
index 26984f49adcd051c3a3fbb3ac5d347e84914e7e8..7189e016e6b505268aebe35690b241427e7ad4fd 100644 (file)
@@ -75,18 +75,6 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
   if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > MULTIBOOT_SEARCH)
     return grub_error (GRUB_ERR_BAD_OS, "program header at a too high offset");
 
-#ifdef MULTIBOOT_LOAD_ELF64
-# ifdef __mips
-  /* We still in 32-bit mode.  */
-  if (ehdr->e_entry < 0xffffffff80000000ULL)
-    return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64");
-# else
-  /* We still in 32-bit mode.  */
-  if (ehdr->e_entry > 0xffffffff)
-    return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64");
-# endif
-#endif
-
   phdr_base = (char *) buffer + ehdr->e_phoff;
 #define phdr(i)                        ((Elf_Phdr *) (phdr_base + (i) * ehdr->e_phentsize))
 
@@ -142,6 +130,19 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
       {
        grub_multiboot_payload_eip = (ehdr->e_entry - phdr(i)->p_vaddr)
          + phdr(i)->p_paddr;
+#ifdef MULTIBOOT_LOAD_ELF64
+# ifdef __mips
+  /* We still in 32-bit mode.  */
+  if ((ehdr->e_entry - phdr(i)->p_vaddr)
+      + phdr(i)->p_paddr < 0xffffffff80000000ULL)
+    return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64");
+# else
+  /* We still in 32-bit mode.  */
+  if ((ehdr->e_entry - phdr(i)->p_vaddr)
+      + phdr(i)->p_paddr > 0xffffffff)
+    return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64");
+# endif
+#endif
        break;
       }