Print this page
sync further changes from uts/aslr

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/grow.c
          +++ new/usr/src/uts/common/os/grow.c
↓ open down ↓ 54 lines elided ↑ open up ↑
  55   55  
  56   56  #include <vm/hat.h>
  57   57  #include <vm/as.h>
  58   58  #include <vm/seg.h>
  59   59  #include <vm/seg_dev.h>
  60   60  #include <vm/seg_vn.h>
  61   61  
  62   62  int use_brk_lpg = 1;
  63   63  int use_stk_lpg = 1;
  64   64  
       65 +/*
       66 + * If set, we will not randomize mappings where the 'addr' argument is
       67 + * non-NULL and not an alignment.
       68 + */
       69 +int aslr_respect_mmap_hint = 0;
       70 +
  65   71  static int brk_lpg(caddr_t nva);
  66   72  static int grow_lpg(caddr_t sp);
  67   73  
  68   74  intptr_t
  69   75  brk(caddr_t nva)
  70   76  {
  71   77          int error;
  72   78          proc_t *p = curproc;
  73   79  
  74   80          /*
  75      -         * As a special case to aid the implementation of sbrk(3C), if given a
  76      -         * new brk of 0, return the current brk.  We'll hide this in brk(3C).
  77      -         */
  78      -        if (nva == 0)
  79      -                return ((intptr_t)(p->p_brkbase + p->p_brksize));
  80      -
  81      -        /*
  82   81           * Serialize brk operations on an address space.
  83   82           * This also serves as the lock protecting p_brksize
  84   83           * and p_brkpageszc.
  85   84           */
  86   85          as_rangelock(p->p_as);
       86 +
       87 +        /*
       88 +         * As a special case to aid the implementation of sbrk(3C), if given a
       89 +         * new brk of 0, return the current brk.  We'll hide this in brk(3C).
       90 +         */
       91 +        if (nva == 0) {
       92 +                as_rangeunlock(p->p_as);
       93 +                return ((intptr_t)(p->p_brkbase + p->p_brksize));
       94 +        }
       95 +
  87   96          if (use_brk_lpg && (p->p_flag & SAUTOLPG) != 0) {
  88   97                  error = brk_lpg(nva);
  89   98          } else {
  90   99                  error = brk_internal(nva, p->p_brkpageszc);
  91  100          }
  92  101          as_rangeunlock(p->p_as);
  93  102          return ((error != 0 ? set_errno(error) : 0));
  94  103  }
  95  104  
  96  105  /*
↓ open down ↓ 491 lines elided ↑ open up ↑
 588  597          vn_a.maxprot = PROT_ALL;
 589  598          vn_a.flags = flags & ~MAP_TYPE;
 590  599          vn_a.cred = CRED();
 591  600          vn_a.amp = NULL;
 592  601          vn_a.szc = 0;
 593  602          vn_a.lgrp_mem_policy_flags = 0;
 594  603  
 595  604          return (as_map(as, *addrp, len, segvn_create, &vn_a));
 596  605  }
 597  606  
      607 +#define RANDOMIZABLE_MAPPING(addr, flags) (((flags & MAP_FIXED) == 0) && \
      608 +        !(((flags & MAP_ALIGN) == 0) && (addr != 0) && aslr_respect_mmap_hint))
      609 +
 598  610  static int
 599  611  smmap_common(caddr_t *addrp, size_t len,
 600  612      int prot, int flags, struct file *fp, offset_t pos)
 601  613  {
 602  614          struct vnode *vp;
 603  615          struct as *as = curproc->p_as;
 604  616          uint_t uprot, maxprot, type;
 605  617          int error;
 606  618          int in_crit = 0;
 607  619  
↓ open down ↓ 14 lines elided ↑ open up ↑
 622  634  
 623  635          if ((flags & (MAP_FIXED | _MAP_RANDOMIZE)) ==
 624  636              (MAP_FIXED | _MAP_RANDOMIZE)) {
 625  637                  return (EINVAL);
 626  638          }
 627  639  
 628  640          /*
 629  641           * If it's not a fixed allocation and mmap ASLR is enabled, randomize
 630  642           * it.
 631  643           */
 632      -        if (((flags & MAP_FIXED) == 0) &&
      644 +        if (RANDOMIZABLE_MAPPING(*addrp, flags) &&
 633  645              secflag_enabled(curproc, PROC_SEC_ASLR))
 634  646                  flags |= _MAP_RANDOMIZE;
 635  647  
 636  648  #if defined(__sparc)
 637  649          /*
 638  650           * See if this is an "old mmap call".  If so, remember this
 639  651           * fact and convert the flags value given to mmap to indicate
 640  652           * the specified address in the system call must be used.
 641  653           * _MAP_NEW is turned set by all new uses of mmap.
 642  654           */
↓ open down ↓ 401 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX