From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IkP5C-0002lM-13 for mharc-grub-devel@gnu.org; Tue, 23 Oct 2007 15:06:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IkP59-0002hq-OJ for grub-devel@gnu.org; Tue, 23 Oct 2007 15:06:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IkP58-0002gB-VH for grub-devel@gnu.org; Tue, 23 Oct 2007 15:06:27 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IkP58-0002fk-Jl for grub-devel@gnu.org; Tue, 23 Oct 2007 15:06:26 -0400 Received: from mailout09.sul.t-online.de ([194.25.134.84] helo=mailout09.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IkP57-00009E-Q6 for grub-devel@gnu.org; Tue, 23 Oct 2007 15:06:26 -0400 Received: from fwd28.aul.t-online.de by mailout09.sul.t-online.com with smtp id 1IkP56-0007tu-05; Tue, 23 Oct 2007 21:06:24 +0200 Received: from [10.3.2.2] (Vsmge6ZZ8hxElu9CuWfrDeuzhqYwzdGQt71wUKzxTmwQK1FlycJReF62ovlqP3fgX5@[217.235.205.199]) by fwd28.aul.t-online.de with esmtp id 1IkP4v-1FRBvE0; Tue, 23 Oct 2007 21:06:13 +0200 Message-ID: <471E4628.9030706@t-online.de> Date: Tue, 23 Oct 2007 21:06:16 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------030004010602010703030003" X-ID: Vsmge6ZZ8hxElu9CuWfrDeuzhqYwzdGQt71wUKzxTmwQK1FlycJReF62ovlqP3fgX5 X-TOI-MSGID: 7a27ace1-4140-4725-a647-65bd01f81acd X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] Fix eisa_mmap evaluation, add memory existence check 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: Tue, 23 Oct 2007 19:06:28 -0000 This is a multi-part message in MIME format. --------------030004010602010703030003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch fixes the broken evaluation of the E801 EISA memory map. The shift was too much, the high word is already shifted :-) The bug was hidden until the E820 memory map evaluation was broken due to the struct packing issue fixed in my last patch. The extra handling of "0x3C00" case is IMO not necessary. Regions are merged a few lines later. During testing, I added a primitive memory to detect such problems early. It was difficult to find why grub crashes during module load. Christian 2007-10-23 Christian Franke * kern/i386/pc/init.c (addr_is_valid): New function. (add_mem_region): Add memory existence check. (grub_machine_init): Fix evaluation of eisa_mmap. --------------030004010602010703030003 Content-Type: text/x-patch; name="grub2-init-eisa_mmap.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-init-eisa_mmap.patch" --- grub2.orig/kern/i386/pc/init.c 2007-10-22 22:22:51.359375000 +0200 +++ grub2/kern/i386/pc/init.c 2007-10-22 22:25:44.546875000 +0200 @@ -83,6 +83,19 @@ make_install_device (void) return grub_prefix; } +/* Check memory address */ +static int +addr_is_valid (grub_addr_t addr) +{ + volatile unsigned char * p = (volatile unsigned char *)addr; + unsigned char x, y; + x = *p; + *p = x ^ 0xcf; + y = *p; + *p = x; + return y == (x ^ 0xcf); +} + /* Add a memory region. */ static void add_mem_region (grub_addr_t addr, grub_size_t size) @@ -91,6 +104,9 @@ add_mem_region (grub_addr_t addr, grub_s /* Ignore. */ return; + if (!(addr + size > addr && addr_is_valid (addr) && addr_is_valid (addr+size-1))) + grub_fatal ("invalid memory region %p - %p", (char*)addr, (char*)addr+size-1); + mem_regions[num_regions].addr = addr; mem_regions[num_regions].size = size; num_regions++; @@ -199,13 +215,8 @@ grub_machine_init (void) if (eisa_mmap) { - if ((eisa_mmap & 0xFFFF) == 0x3C00) - add_mem_region (0x100000, (eisa_mmap << 16) + 0x100000 * 15); - else - { - add_mem_region (0x100000, (eisa_mmap & 0xFFFF) << 10); - add_mem_region (0x1000000, eisa_mmap << 16); - } + add_mem_region (0x100000, (eisa_mmap & 0xFFFF) << 10); + add_mem_region (0x1000000, eisa_mmap & ~0xFFFF); } else add_mem_region (0x100000, grub_get_memsize (1) << 10); --------------030004010602010703030003--