From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JGxvO-0007RQ-Nh for mharc-grub-devel@gnu.org; Mon, 21 Jan 2008 09:46:58 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JGxvM-0007PJ-6g for grub-devel@gnu.org; Mon, 21 Jan 2008 09:46:56 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JGxvH-0007Lr-5o for grub-devel@gnu.org; Mon, 21 Jan 2008 09:46:55 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JGxvG-0007Lj-S2 for grub-devel@gnu.org; Mon, 21 Jan 2008 09:46:50 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JGxvG-0003fm-Fb for grub-devel@gnu.org; Mon, 21 Jan 2008 09:46:50 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JGxv8-0000bN-J3 for grub-devel@gnu.org; Mon, 21 Jan 2008 15:46:49 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1JGxtS-0001Ln-3b for grub-devel@gnu.org; Mon, 21 Jan 2008 15:44:58 +0100 Date: Mon, 21 Jan 2008 15:44:58 +0100 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20080121144458.GA5144@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="d6Gm4EdcadzBjdND" Content-Disposition: inline Content-Transfer-Encoding: 8bit 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.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH] abort when core.img is too big 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: Mon, 21 Jan 2008 14:46:56 -0000 --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit With the addition of memdisk, it is too easy for user to create an image big enough that would corrupt upper memory (starting with vga region). This happens at roughly ~600 kiB memdisk size. This patch adds a check in grub-mkimage to prevent this. I did also take the opportunity to reuse the upper memory macro to avoid hardcoding its address for VGA stuff. Comments? -- Robert Millan I know my rights; I want my phone call! What use is a phone call… if you are unable to speak? (as seen on /.) --d6Gm4EdcadzBjdND Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="size_limit.diff" * conf/i386-pc.rmk (GRUB_MEMORY_MACHINE_LINK_ADDR): New variable. (kernel_img_LDFLAGS): Use `GRUB_MEMORY_MACHINE_LINK_ADDR' as link address. (grub_mkimage_CFLAGS): Propagate `GRUB_MEMORY_MACHINE_LINK_ADDR' as a C macro. * include/grub/i386/pc/memory.h (GRUB_MEMORY_MACHINE_UPPER): New macro. Indicates start of upper memory. * util/i386/pc/grub-mkimage.c: Include `'. (generate_image): Abort when image size is big enough to corrupt upper memory. * include/grub/i386/pc/vga.h: Include `'. (GRUB_MEMORY_MACHINE_VGA_ADDR): Alias for `GRUB_MEMORY_MACHINE_UPPER'. * term/i386/pc/vga.c (VGA_MEM): Use `GRUB_MEMORY_MACHINE_VGA_ADDR' instead of hardcoding 0xA0000. * video/i386/pc/vbe.c: Include `'. (grub_vbe_set_video_mode): Use `GRUB_MEMORY_MACHINE_VGA_ADDR' instead of hardcoding 0xA0000. diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/conf/i386-pc.rmk ./conf/i386-pc.rmk --- ../grub2/conf/i386-pc.rmk 2008-01-21 00:41:58.000000000 +0100 +++ ./conf/i386-pc.rmk 2008-01-21 14:21:43.000000000 +0100 @@ -1,5 +1,7 @@ # -*- makefile -*- +GRUB_MEMORY_MACHINE_LINK_ADDR = 0x8200 + COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib @@ -42,7 +44,7 @@ kernel_img_HEADERS = arg.h boot.h cache. machine/memory.h machine/loader.h machine/vga.h machine/vbe.h machine/kernel.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,8200 $(COMMON_CFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst @@ -63,6 +65,7 @@ endif # For grub-mkimage. grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \ util/resolve.c +grub_mkimage_CFLAGS = -DGRUB_MEMORY_MACHINE_LINK_ADDR=$(GRUB_MEMORY_MACHINE_LINK_ADDR) grub_mkimage_LDFLAGS = $(LIBLZO) # For grub-setup. diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/include/grub/i386/pc/memory.h ./include/grub/i386/pc/memory.h --- ../grub2/include/grub/i386/pc/memory.h 2008-01-21 00:41:58.000000000 +0100 +++ ./include/grub/i386/pc/memory.h 2008-01-21 15:22:02.000000000 +0100 @@ -1,7 +1,7 @@ /* memory.h - describe the memory map */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,9 @@ /* The size of the protect mode stack. */ #define GRUB_MEMORY_MACHINE_PROT_STACK_SIZE 0x8000 +/* The upper memory area (starting at 640 kiB). */ +#define GRUB_MEMORY_MACHINE_UPPER 0xa0000 + /* The protected mode stack. */ #define GRUB_MEMORY_MACHINE_PROT_STACK \ (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + GRUB_MEMORY_MACHINE_SCRATCH_SIZE \ diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/include/grub/i386/pc/vga.h ./include/grub/i386/pc/vga.h --- ../grub2/include/grub/i386/pc/vga.h 2007-07-22 01:32:24.000000000 +0200 +++ ./include/grub/i386/pc/vga.h 2008-01-21 15:22:58.000000000 +0100 @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,10 @@ #define GRUB_VGA_MACHINE_HEADER 1 #include +#include + +/* The VGA (at the beginning of upper memory). */ +#define GRUB_MEMORY_MACHINE_VGA_ADDR GRUB_MEMORY_MACHINE_UPPER /* Set the video mode to MODE and return the previous mode. */ unsigned char EXPORT_FUNC(grub_vga_set_mode) (unsigned char mode); diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/term/i386/pc/vga.c ./term/i386/pc/vga.c --- ../grub2/term/i386/pc/vga.c 2007-12-25 12:10:47.000000000 +0100 +++ ./term/i386/pc/vga.c 2008-01-21 15:23:38.000000000 +0100 @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000,2001,2002,2003,2004,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,7 @@ #define CHAR_HEIGHT 16 #define TEXT_WIDTH (VGA_WIDTH / CHAR_WIDTH) #define TEXT_HEIGHT (VGA_HEIGHT / CHAR_HEIGHT) -#define VGA_MEM ((unsigned char *) 0xA0000) +#define VGA_MEM ((grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR) #define PAGE_OFFSET(x) ((x) * (VGA_WIDTH * VGA_HEIGHT / 8)) #define DEFAULT_FG_COLOR 0xa diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/util/i386/pc/grub-mkimage.c ./util/i386/pc/grub-mkimage.c --- ../grub2/util/i386/pc/grub-mkimage.c 2008-01-21 00:41:59.000000000 +0100 +++ ./util/i386/pc/grub-mkimage.c 2008-01-21 15:23:56.000000000 +0100 @@ -1,7 +1,7 @@ /* grub-mkimage.c - make a bootable image */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,10 @@ generate_image (const char *dir, char *p = grub_cpu_to_le32 (memdisk_size); *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE)) = grub_cpu_to_le32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE); + + if (core_size > GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR) + grub_util_error ("Core image is too big (%p > %p)\n", core_size, + GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR); grub_util_write_image (core_img, core_size, out); free (kernel_img); diff -x CVS -x '*~' -x '*.mk' -urp ../grub2/video/i386/pc/vbe.c ./video/i386/pc/vbe.c --- ../grub2/video/i386/pc/vbe.c 2008-01-01 13:02:06.000000000 +0100 +++ ./video/i386/pc/vbe.c 2008-01-21 14:22:52.000000000 +0100 @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -193,7 +194,7 @@ grub_vbe_set_video_mode (grub_uint32_t m if (mode < 0x100) { /* If this is not a VESA mode, guess address. */ - framebuffer.ptr = (grub_uint8_t *) 0xA0000; + framebuffer.ptr = (grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR; framebuffer.index_color_mode = 1; } else --d6Gm4EdcadzBjdND--