From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LiEN6-00012s-HQ for mharc-grub-devel@gnu.org; Fri, 13 Mar 2009 16:52:48 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LiEN5-00012l-Fj for grub-devel@gnu.org; Fri, 13 Mar 2009 16:52:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LiEN1-00011K-UT for grub-devel@gnu.org; Fri, 13 Mar 2009 16:52:47 -0400 Received: from [199.232.76.173] (port=43710 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LiEN1-00011B-Ro for grub-devel@gnu.org; Fri, 13 Mar 2009 16:52:43 -0400 Received: from mail-fx0-f176.google.com ([209.85.220.176]:42063) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LiEN1-0002x4-9G for grub-devel@gnu.org; Fri, 13 Mar 2009 16:52:43 -0400 Received: by fxm24 with SMTP id 24so2939325fxm.42 for ; Fri, 13 Mar 2009 13:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type; bh=sQ5D9KRYxhVaX9hR6wK+HNwqaqs1i2ns372RG/YanrE=; b=vXVp34tOyPLSQxpxCTcRcf+7nqL+vzz2/Xyvk1pBbUOtbG60QpGfCarx+3bugYneHy GLSeu7F/1Oo18qDzaY6tAmjH5S9l63qGiUPRB4xby5LJI8h+JDu39K+wjd/H4Uto+8sA NzpDUTUWARHPfCyqsRHp/9NYUI4fuwchYa33U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; b=OH9RJKowHyiFSlcmZjja2W1n4M5YKF2RuaShqClrlhvWl5vsLG1kJHzhxXjx14HDt1 baRW+JohwsSe79QoDG6/i+wB2GHh9n0VARJzALTa16fs3WUYMdsbenCS1Jub2s4bOtD9 V9dUgBrBQZYWaaNuFf8QXTgma6VLmnf56kckY= Received: by 10.103.220.18 with SMTP id x18mr873889muq.38.1236977561665; Fri, 13 Mar 2009 13:52:41 -0700 (PDT) Received: from ?192.168.1.25? (7.86.202.62.cust.bluewin.ch [62.202.86.7]) by mx.google.com with ESMTPS id g1sm4504185muf.42.2009.03.13.13.52.40 (version=SSLv3 cipher=RC4-MD5); Fri, 13 Mar 2009 13:52:41 -0700 (PDT) Message-ID: <49BAC797.9010200@gmail.com> Date: Fri, 13 Mar 2009 21:52:39 +0100 From: phcoder User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: The development of GRUB 2 References: <49B82B65.3080506@gmail.com> <20090313191442.GC17068@thorin> <49BAC506.2030006@gmail.com> <20090313.134505.185970759.davem@davemloft.net> In-Reply-To: <20090313.134505.185970759.davem@davemloft.net> Content-Type: multipart/mixed; boundary="------------080200050205020207070708" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: ELF bugfixes X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2009 20:52:47 -0000 This is a multi-part message in MIME format. --------------080200050205020207070708 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit David Miller wrote: > From: phcoder > 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 --------------080200050205020207070708 Content-Type: text/x-diff; name="elffixes.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="elffixes.diff" Index: ChangeLog =================================================================== --- ChangeLog (revision 2036) +++ ChangeLog (working copy) @@ -1,3 +1,11 @@ +2009-03-01 Vladimir Serbinenko + + 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 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 --------------080200050205020207070708--