All of lore.kernel.org
 help / color / mirror / Atom feed
From: phcoder <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: ELF bugfixes
Date: Fri, 13 Mar 2009 21:52:39 +0100	[thread overview]
Message-ID: <49BAC797.9010200@gmail.com> (raw)
In-Reply-To: <20090313.134505.185970759.davem@davemloft.net>

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

David Miller wrote:
> From: phcoder <phcoder@gmail.com>
> Date: Fri, 13 Mar 2009 21:41:42 +0100
> 
>> Actually our segment table is also our table for transforming
>> between virtual and physical address. I don't see why entry point
>> would be defined against virtual address of lowest physical segement
> 
> I would suggest simply looping over the phdrs and remembering
> which one the e_entry falls into.
> 
> Won't that make things work in the case you're describing?
> 
I thought I have attached new patch. Sorry forgot to do so

-- 

Regards
Vladimir 'phcoder' Serbinenko


[-- Attachment #2: elffixes.diff --]
[-- Type: text/x-diff, Size: 2694 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2036)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2009-03-01  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	Bugfixes in multiboot for bugs uncovered by solaris kernel
+
+	* loader/i386/multiboot_elfxx.c (grub_multiboot_load_elf): corrected 
+	limit detection
+	Use vaddr of correct segment for entry_point 
+
 2009-03-12  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	Parttool
Index: loader/i386/multiboot_elfxx.c
===================================================================
--- loader/i386/multiboot_elfxx.c	(revision 2036)
+++ loader/i386/multiboot_elfxx.c	(working copy)
@@ -49,7 +49,7 @@
 {
   Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
   char *phdr_base;
-  int lowest_segment = 0, highest_segment = 0;
+  int lowest_segment = -1, highest_segment = -1;
   int i;
 
   if (ehdr->e_ident[EI_CLASS] != ELFCLASSXX)
@@ -83,11 +83,17 @@
   for (i = 0; i < ehdr->e_phnum; i++)
     if (phdr(i)->p_type == PT_LOAD && phdr(i)->p_filesz != 0)
       {
-	if (phdr(i)->p_paddr < phdr(lowest_segment)->p_paddr)
+	if (lowest_segment == -1 
+	    || phdr(i)->p_paddr < phdr(lowest_segment)->p_paddr)
 	  lowest_segment = i;
-	if (phdr(i)->p_paddr > phdr(highest_segment)->p_paddr)
+	if (highest_segment == -1
+	    || phdr(i)->p_paddr > phdr(highest_segment)->p_paddr)
 	  highest_segment = i;
       }
+
+  if (lowest_segment == -1)
+    return grub_error (GRUB_ERR_BAD_OS, "ELF contains no loadable segments");
+
   code_size = (phdr(highest_segment)->p_paddr + phdr(highest_segment)->p_memsz) - phdr(lowest_segment)->p_paddr;
   grub_multiboot_payload_dest = phdr(lowest_segment)->p_paddr;
 
@@ -105,8 +111,8 @@
         {
 	  char *load_this_module_at = (char *) (grub_multiboot_payload_orig + (long) (phdr(i)->p_paddr - phdr(lowest_segment)->p_paddr));
 
-	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx\n",
-			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz);
+	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
+			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
 
 	  if (grub_file_seek (file, (grub_off_t) phdr(i)->p_offset)
 	      == (grub_off_t) -1)
@@ -124,7 +130,11 @@
         }
     }
 
-  grub_multiboot_payload_entry_offset = ehdr->e_entry - phdr(lowest_segment)->p_vaddr;
+  for (i = 0; i < ehdr->e_phnum; i++)
+    if (phdr(i)->p_vaddr <= ehdr->e_entry 
+	&& phdr(i)->p_vaddr + phdr(i)->p_memsz > ehdr->e_entry)
+      grub_multiboot_payload_entry_offset = (ehdr->e_entry - phdr(i)->p_vaddr)
+	+ (phdr(i)->p_paddr  - phdr(lowest_segment)->p_paddr);
 
 #undef phdr
 


  reply	other threads:[~2009-03-13 20:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-02  0:35 ELF bugfixes phcoder
2009-03-11 21:15 ` Robert Millan
2009-03-11 21:21   ` phcoder
2009-03-12  8:23     ` phcoder
2009-03-12  9:07       ` David Miller
2009-03-13 19:14     ` Robert Millan
2009-03-13 20:41       ` phcoder
2009-03-13 20:45         ` David Miller
2009-03-13 20:52           ` phcoder [this message]
2009-03-18 10:12             ` Robert Millan
2009-03-18 13:26               ` phcoder
2009-03-21 17:46                 ` Robert Millan
2009-03-21 17:58                   ` phcoder
2009-03-21 18:03                     ` Robert Millan
2009-03-21 18:05                       ` phcoder
2009-03-21 22:03                         ` Robert Millan
2009-03-21 22:49                           ` phcoder
2009-03-21 23:02                             ` Robert Millan
2009-03-21 22:55                           ` Robert Millan
2009-03-13 22:46         ` Robert Millan
2009-03-13 23:01           ` phcoder
2009-03-14 14:53             ` Robert Millan
2009-03-15 21:30           ` phcoder
     [not found] <49B8F067.2040503@gmail.com>
     [not found] ` <20090312.055819.95768237.davem@davemloft.net>
     [not found]   ` <49B90C69.60703@gmail.com>
     [not found]     ` <20090312.062628.260166400.davem@davemloft.net>
2009-03-12 13:43       ` phcoder
2009-03-12 14:05         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49BAC797.9010200@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.