source: patches/grub-0.97-use_mmap-1.patch@ 392a73c

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 392a73c was 8f78e14, checked in by Jim Gifford <clfs@…>, 18 years ago

Added: grub-0.97-use_mmap-1.patch

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[8f78e14]1Submitted By: Jim Gifford <jim@linuxfromscratch.org>
2Date: 07-14-2006
3Initial Package Version: 0.97
4Upstream Status: Unknown
5Origin: Grub Bug Report - http://savannah.gnu.org/bugs/?func=detailitem&item_id=11312
6Description: This patch fixes the following issues on x86_64
7 1) malloc'd pages seem to lack the execute bit on x86_64;
8 2) grub seems to use some stack pointer diversion to malloc'd pages;
9 3) nested functions execute data on the stack;
10 4) this causes a segfault (at least on my machine)
11
12diff -Naur grub-0.97.orig/grub/asmstub.c grub-0.97/grub/asmstub.c
13--- grub-0.97.orig/grub/asmstub.c 2005-02-16 12:45:14.000000000 -0800
14+++ grub-0.97/grub/asmstub.c 2006-07-14 12:38:08.305902933 -0700
15@@ -43,6 +43,8 @@
16 #include <termios.h>
17 #include <signal.h>
18
19+#include <sys/mman.h>
20+
21 #ifdef __linux__
22 # include <sys/ioctl.h> /* ioctl */
23 # if !defined(__GLIBC__) || \
24@@ -142,14 +144,25 @@
25 }
26
27 assert (grub_scratch_mem == 0);
28- scratch = malloc (0x100000 + EXTENDED_MEMSIZE + 15);
29+ scratch = mmap(NULL,
30+ 0x100000 + EXTENDED_MEMSIZE + 15,
31+ PROT_EXEC | PROT_READ | PROT_WRITE,
32+ MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_32BIT,
33+ -1,
34+ 0);
35+
36 assert (scratch);
37 grub_scratch_mem = (char *) ((((int) scratch) >> 4) << 4);
38
39 /* FIXME: simulate the memory holes using mprot, if available. */
40
41 assert (disks == 0);
42- disks = malloc (NUM_DISKS * sizeof (*disks));
43+ disks = mmap(NULL,
44+ NUM_DISKS * sizeof (*disks),
45+ PROT_EXEC | PROT_READ | PROT_WRITE,
46+ MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_32BIT,
47+ -1,
48+ 0);
49 assert (disks);
50 /* Initialize DISKS. */
51 for (i = 0; i < NUM_DISKS; i++)
52@@ -215,9 +228,9 @@
53 /* Release memory. */
54 restore_device_map (device_map);
55 device_map = 0;
56- free (disks);
57+ munmap(disks, NUM_DISKS * sizeof (*disks));
58 disks = 0;
59- free (scratch);
60+ munmap(scratch, 0x100000 + EXTENDED_MEMSIZE + 15);
61 grub_scratch_mem = 0;
62
63 if (serial_device)
Note: See TracBrowser for help on using the repository browser.