Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LlAD6-0004H2-8A for mharc-grub-devel@gnu.org; Sat, 21 Mar 2009 19:02:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LlAD4-0004GX-Fc for grub-devel@gnu.org; Sat, 21 Mar 2009 19:02:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LlAD0-0004Fg-NM for grub-devel@gnu.org; Sat, 21 Mar 2009 19:02:34 -0400 Received: from [199.232.76.173] (port=58902 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LlAD0-0004Fd-J4 for grub-devel@gnu.org; Sat, 21 Mar 2009 19:02:30 -0400 Received: from aybabtu.com ([69.60.117.155]:39974) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LlACz-0004HC-Uc for grub-devel@gnu.org; Sat, 21 Mar 2009 19:02:30 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtp (Exim 4.69) (envelope-from ) id 1LlA3j-0006ev-Tp for grub-devel@gnu.org; Sat, 21 Mar 2009 23:52:56 +0100 Received: from rmh by thorin with local (Exim 4.69) (envelope-from ) id 1LlACw-0007cx-OL for grub-devel@gnu.org; Sun, 22 Mar 2009 00:02:26 +0100 Date: Sun, 22 Mar 2009 00:02:26 +0100 From: Robert Millan To: The development of GRUB 2 Message-ID: <20090321230226.GB19948@thorin> References: <20090313.134505.185970759.davem@davemloft.net> <49BAC797.9010200@gmail.com> <20090318101227.GB20072@thorin> <49C0F690.7060305@gmail.com> <20090321174629.GB18284@thorin> <49C52AE2.5070202@gmail.com> <20090321180315.GF18284@thorin> <49C52C63.4050904@gmail.com> <20090321220312.GA19598@thorin> <49C56EEE.50809@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49C56EEE.50809@gmail.com> Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.18 (2008-05-17) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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: Sat, 21 Mar 2009 23:02:34 -0000 Committed. On Sat, Mar 21, 2009 at 11:49:18PM +0100, phcoder wrote: > Robert Millan wrote: >> On Sat, Mar 21, 2009 at 07:05:23PM +0100, phcoder wrote: >>> Robert Millan wrote: >>>> On Sat, Mar 21, 2009 at 06:58:58PM +0100, phcoder wrote: >>>>> Robert Millan wrote: >>>>>> On Wed, Mar 18, 2009 at 02:26:40PM +0100, phcoder wrote: >>>>>>> Robert Millan wrote: >>>>>>>> On Fri, Mar 13, 2009 at 09:52:39PM +0100, phcoder wrote: >>>>>>>>> - 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); >>>>>>>> You need to handle the case in which grub_multiboot_payload_entry_offset is left >>>>>>>> uninitialized (it needs to be initialized each time the multiboot command is >>>>>>>> run, not just when the module is loaded). >>>>>>>> >>>>>>> module? actually it's when loading image. Perhaps you mean >>>>>>> that additional error check is necessary >>>>>> I meant GRUB's multiboot.mod, not the payload's module. Sorry I wasn't clear. >>>>>> >>>>> With this error check if grub_multiboot_payload_entry_offset it >>>>> can happen only if no image is loaded. And actually >>>>> grub_multiboot_payload_entry_offset is set to 0 at multiboot.mod >>>>> load >>>>> So I don't really understand the problem >>>> You can't rely on grub_multiboot_payload_entry_offset being set to 0, because >>>> any subsequent call of "multiboot /something" has the potential to override >>>> this. You must not assume the multiboot command is only going to be run once. >>>> >>> No but it always corresponds to the current image. It's set either in >>> multiboot.c or in grub_multiboot_load_elf >> >> It is now, but your code makes this conditional. >> > > > -- > > Regards > Vladimir 'phcoder' Serbinenko > diff --git a/loader/i386/multiboot_elfxx.c b/loader/i386/multiboot_elfxx.c > index 801800c..ce9e4fe 100644 > --- a/loader/i386/multiboot_elfxx.c > +++ b/loader/i386/multiboot_elfxx.c > @@ -49,7 +49,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) > { > 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,18 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) > 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) > + /* Beware that segment 0 isn't necessarily loadable */ > + 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 +112,8 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) > { > 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 +131,17 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer) > } > } > > - 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); > + break; > + } > + > + if (i == ehdr->e_phnum) > + return grub_error (GRUB_ERR_BAD_OS, "entry point isn't in a segment"); > > #undef phdr > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel -- Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."