source: patches/grub-0.97-use_mmap-1.patch@ 01f18dc9

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 01f18dc9 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
  • grub/asmstub.c

    Submitted By: Jim Gifford <jim@linuxfromscratch.org>
    Date: 07-14-2006
    Initial Package Version: 0.97
    Upstream Status: Unknown
    Origin: Grub Bug Report - http://savannah.gnu.org/bugs/?func=detailitem&item_id=11312
    Description: This patch fixes the following issues on x86_64
    	1) malloc'd pages seem to lack the execute bit on x86_64;
    	2) grub seems to use some stack pointer diversion to malloc'd pages;
    	3) nested functions execute data on the stack;
    	4) this causes a segfault (at least on my machine)
    
    diff -Naur grub-0.97.orig/grub/asmstub.c grub-0.97/grub/asmstub.c
    old new  
    4343#include <termios.h>
    4444#include <signal.h>
    4545
     46#include <sys/mman.h>
     47
    4648#ifdef __linux__
    4749# include <sys/ioctl.h>         /* ioctl */
    4850# if !defined(__GLIBC__) || \
     
    142144    }
    143145
    144146  assert (grub_scratch_mem == 0);
    145   scratch = malloc (0x100000 + EXTENDED_MEMSIZE + 15);
     147  scratch = mmap(NULL,
     148                 0x100000 + EXTENDED_MEMSIZE + 15,
     149                 PROT_EXEC | PROT_READ | PROT_WRITE,
     150                 MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_32BIT,
     151                 -1,
     152                 0);
     153
    146154  assert (scratch);
    147155  grub_scratch_mem = (char *) ((((int) scratch) >> 4) << 4);
    148156
    149157  /* FIXME: simulate the memory holes using mprot, if available. */
    150158
    151159  assert (disks == 0);
    152   disks = malloc (NUM_DISKS * sizeof (*disks));
     160  disks = mmap(NULL,
     161               NUM_DISKS * sizeof (*disks),
     162               PROT_EXEC | PROT_READ | PROT_WRITE,
     163               MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_32BIT,
     164               -1,
     165               0);
    153166  assert (disks);
    154167  /* Initialize DISKS.  */
    155168  for (i = 0; i < NUM_DISKS; i++)
     
    215228  /* Release memory. */
    216229  restore_device_map (device_map);
    217230  device_map = 0;
    218   free (disks);
     231  munmap(disks, NUM_DISKS * sizeof (*disks));
    219232  disks = 0;
    220   free (scratch);
     233  munmap(scratch, 0x100000 + EXTENDED_MEMSIZE + 15);
    221234  grub_scratch_mem = 0;
    222235
    223236  if (serial_device)
Note: See TracBrowser for help on using the repository browser.