Print this page
11838 secflag tests are racy

Split Close
Expand all
Collapse all
          --- old/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh
          +++ new/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh
↓ open down ↓ 5 lines elided ↑ open up ↑
   6    6  # You may only use this file in accordance with the terms of version
   7    7  # 1.0 of the CDDL.
   8    8  #
   9    9  # A full copy of the text of the CDDL should have accompanied this
  10   10  # source.  A copy of the CDDL is also available via the Internet at
  11   11  # http://www.illumos.org/license/CDDL.
  12   12  #
  13   13  
  14   14  #
  15   15  # Copyright 2015, Richard Lowe.
       16 +# Copyright 2019 Joyent, Inc.
  16   17  #
  17   18  
       19 +# check secflags, waiting a little bit for the change to happen
       20 +secflags() {
       21 +    sleep 1
       22 +    /usr/bin/psecflags $*
       23 +}
       24 +
  18   25  mkdir /tmp/$$-secflags-test
  19   26  cd /tmp/$$-secflags-test
  20   27  
  21   28  /usr/bin/psecflags -s none $$   # Clear ourselves out
  22   29  cat > expected <<EOF
  23   30          I:      none
  24   31  EOF
  25   32  
  26      -/usr/bin/psecflags $$ | grep I: > output
       33 +secflags $$ | grep I: > output
  27   34  diff -u expected output || exit 1 # Make sure the setting of 'none' worked
  28   35  
  29   36  cleanup() {
  30   37      cd /
  31   38      rm -fr /tmp/$$-secflags-test
  32   39  }
  33   40  trap cleanup EXIT
  34   41  
  35   42  ## Tests of manipulating a running process (ourselves)
  36   43  
  37   44  self_set() {
  38   45      echo "Set (self)"
  39   46      /usr/bin/psecflags -s aslr $$
  40   47  
  41   48      cat > expected <<EOF
  42   49          I:      aslr
  43   50  EOF
  44   51  
  45      -    /usr/bin/psecflags $$ | grep I: > output
       52 +    secflags $$ | grep I: > output
  46   53      diff -u expected output || exit 1
  47   54  }
  48   55  
  49   56  self_add() {
  50   57      echo "Add (self)"
  51   58      /usr/bin/psecflags -s current,noexecstack $$
  52   59      cat > expected <<EOF
  53   60          I:      aslr,noexecstack
  54   61  EOF
  55   62  
  56      -    /usr/bin/psecflags $$ | grep I: > output
       63 +    secflags $$ | grep I: > output
  57   64      diff -u expected output || exit 1
  58   65  }
  59   66  
  60   67  self_remove() {
  61   68      echo "Remove (self)"
  62   69      /usr/bin/psecflags -s current,-aslr $$
  63   70      cat > expected <<EOF
  64   71          I:      noexecstack
  65   72  EOF
  66   73  
  67      -    /usr/bin/psecflags $$ | grep I: > output
       74 +    secflags $$ | grep I: > output
  68   75      diff -u expected output || exit 1
  69   76  }
  70   77  
  71   78  self_all() {
  72   79      echo "All (self)"
  73   80      /usr/bin/psecflags -s all $$
  74      -    /usr/bin/psecflags $$ | grep -q 'I:.*,.*,' || exit 1 # This is lame, but functional
       81 +    secflags $$ | grep -q 'I:.*,.*,' || exit 1 # This is lame, but functional
  75   82  }
  76   83  
  77   84  self_none() {
  78   85      echo "None (self)"
  79   86      /usr/bin/psecflags -s all $$
  80   87      /usr/bin/psecflags -s none $$
  81   88      cat > expected <<EOF
  82   89          I:      none
  83   90  EOF
  84      -    /usr/bin/psecflags $$ | grep I: > output
       91 +    secflags $$ | grep I: > output
  85   92      diff -u expected output || exit 1
  86   93  }
  87   94  
  88   95  child_set() {
  89   96      echo "Set (child)"
  90   97  
  91      -    typeset pid; 
       98 +    typeset pid;
  92   99  
  93  100      /usr/bin/psecflags -s aslr -e sleep 10000 &
  94  101      pid=$!
  95  102      cat > expected <<EOF
  96  103          E:      aslr
  97  104          I:      aslr
  98  105  EOF
  99      -    /usr/bin/psecflags $pid | grep '[IE]:' > output
      106 +    secflags $pid | grep '[IE]:' > output
 100  107      kill $pid
 101  108      diff -u expected output || exit 1
 102  109  }
 103  110  
 104  111  child_add() {
 105  112      echo "Add (child)"
 106  113  
 107      -    typeset pid; 
      114 +    typeset pid;
 108  115  
 109  116      /usr/bin/psecflags -s aslr $$
 110  117      /usr/bin/psecflags -s current,noexecstack -e sleep 10000 &
 111  118      pid=$!
 112  119      cat > expected <<EOF
 113  120          E:      aslr,noexecstack
 114  121          I:      aslr,noexecstack
 115  122  EOF
 116      -    /usr/bin/psecflags $pid | grep '[IE]:' > output
      123 +    secflags $pid | grep '[IE]:' > output
 117  124      kill $pid
 118  125      /usr/bin/psecflags -s none $$
 119  126      diff -u expected output || exit 1
 120  127  }
 121  128  
 122  129  child_remove() {
 123  130      echo "Remove (child)"
 124  131  
 125      -    typeset pid; 
      132 +    typeset pid;
 126  133  
 127  134      /usr/bin/psecflags -s aslr $$
 128  135      /usr/bin/psecflags -s current,-aslr -e sleep 10000 &
 129  136      pid=$!
 130  137      cat > expected <<EOF
 131  138          E:      none
 132  139          I:      none
 133  140  EOF
 134      -    /usr/bin/psecflags $pid | grep '[IE]:' > output
      141 +    secflags $pid | grep '[IE]:' > output
 135  142      kill $pid
 136  143      /usr/bin/psecflags -s none $$
 137  144      diff -u expected output || exit 1
 138  145  }
 139  146  
 140  147  child_all() {
 141  148      echo "All (child)"
 142  149  
 143  150      typeset pid ret
 144  151  
 145  152      /usr/bin/psecflags -s all -e sleep 10000 &
 146  153      pid=$!
 147      -    /usr/bin/psecflags $pid | grep -q 'E:.*,.*,' # This is lame, but functional
      154 +    secflags $pid | grep -q 'E:.*,.*,' # This is lame, but functional
 148  155      ret=$?
 149  156      kill $pid
 150  157      (( $ret != 0 )) && exit $ret
 151  158  }
 152  159  
 153  160  child_none() {
 154  161      echo "None (child)"
 155  162  
 156  163      typeset pid
 157      -    
      164 +
 158  165      /usr/bin/psecflags -s all $$
 159  166  
 160  167      /usr/bin/psecflags -s none -e sleep 10000 &
 161  168      pid=$!
 162  169      cat > expected <<EOF
 163  170          E:      none
 164  171          I:      none
 165  172  EOF
 166      -    /usr/bin/psecflags $pid | grep '[IE]:' > output
      173 +    secflags $pid | grep '[IE]:' > output
 167  174      kill $pid
 168  175      diff -u expected output || exit 1
 169  176  }
 170  177  
 171  178  list() {
 172  179      echo "List"
 173  180      cat > expected<<EOF
 174  181  aslr
 175  182  forbidnullmap
 176  183  noexecstack
↓ open down ↓ 19 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX