| [8f78e14] | 1 | Submitted By: Jim Gifford <jim@linuxfromscratch.org> | 
|---|
|  | 2 | Date: 07-14-2006 | 
|---|
|  | 3 | Initial Package Version: 0.97 | 
|---|
|  | 4 | Upstream Status: Unknown | 
|---|
|  | 5 | Origin: Grub Bug Report - http://savannah.gnu.org/bugs/?func=detailitem&item_id=11312 | 
|---|
|  | 6 | Description: 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 |  | 
|---|
|  | 12 | diff -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) | 
|---|